git cloneit and go to the directory it lives in to start working.
project-name/which you can
git inita repository in and start working on.
source activate venv-folder/bin/activate(or, if you are on Windows,
venv-folder\Scripts\activate.bat) in order to activate the virtual environment.
requirements.txtat the root. Run
requirements.txtis listed below:
your_projectcontaining a single app called
manage.py: the main helper script for developing with Django. Can start the server, run db operations, etc
your-project/: Your main project folder, where all of your code goes. This will have a few sub-files, as denoted by sub-bullets (sub-folders are discussed in a later section)
settings.py: Where all of Django's settings are stored. This file is massive, an absolute unit. Specifics discussed later.
urls.py: Where Django looks for all the URLs it should handle. URLs can be manually specified, included from other files, and all correspond to Views defined in Apps (next section)
wsgi.py: A small file containing everything needed for a Django server to actually server your app. Doesn't really need to be edited
the_app/) in the main project directory () In the Othello Server, for example, there is one app each dedicated to:
games, the biggest one)
urls.pyfile or, for more complicated apps, an app-specific
the-app/urls.pyfile which in turn is included in bulk in the main
urls.pyfile. Got it?
python manage.py makemigrations && python manage.py migrate
admin.pydefines models accessible from django-admin, and
tests.pydefines testcases so you have a less chance of breaking your code by accident (super lame).
.html. We don't really do that yet though.
your_project/static/contains all of the static files, like most of your JS/CSS and all of your images. Note that this folder only really has to be here for debugging purposes: in production, Django won't touch it.
DEBUG: controls whether we are in debug mode or not, will enable static file hosting and automatic server reload when set to
ALLOWED_HOSTS: All the hostnames Django will allow itself to be accessed from.
"127.0.0.1"should be in there if you are developing.
INSTALLED_APPS: All the Apps that Django will load. If you want to add an App you made to the list, append
MIDDLEWARE: some hoodoo-vooodoo black-magic security wizardry, best not to touch it unless a library says you should add them to it.
ROOT_URLCONF: The file Django loads urls from. Should be set to
your_project.urlsby default and stay that way.
TEMPLATES: I don't even know, man. Best not to touch it.
LOGGING: All the places for Django to log it's runtime messages. You should read the actual documentation for this.
WSGI_APPLICATION: The file a Django server should hook into in order to start the server. Why it is called WSGI will be covered later.
DATABASES: All the places Django should store data
python manage.py runserver 8001and go to
http://localhost:8001/randnumto (hopefully) see your random number!
DEBUG=Trueis set in your
settings.py, then you can run
daphneas an example production server, here's what a complete startup script would look like:
ExecStart=/usr/bin/bash your-script.shto a systemd unit to make it the server at boot if that's what you want.