Setup a Django Project (1.4 or later)
-
Create your virtualenv, install stuff.
mkvirtualenv new_project pip install django pip install south # db migration manager for django -
Start up a django project.
mkdir new_project cd ./new_project django-admin.py startproject new_projectStart project will generate the following:
new_project/ new_project/ new_project/ # project-level items new_app/ __init__.py models.py tests.py views.py manage.py -
Setup
local_settings.pyfor environment-specific settings (e.g. DB info, dev apps, etc...). Anything you place inlocal_settings.pywill only run locally.Add the following to the bottom of
settings.pytry: LOCAL_SETTINGS except NameError: try: from local_settings import * except ImportError: passCreate a
local_settings.pyfile in the same directory assettings.pystarting with the lines below. All dev specific go here.LOCAL_SETTINGS = True from settings import * DEBUG = True -
Setup your databases.
Copy
DATABASESfromsettings.pyintolocal_settings.pyand enter the information.DATABASES = { 'default': { ... } }Add
southtoINSTALLED_APPSinsettings.pyINSTALLED_APPS = ( ... 'south', )Perform a
syncdbto create all of your initial datbaase tables.python ./manage.py syncdb -
Run the development server to make sure everyone's happy
python ./manage.py runserverYou should see a Django generated 404 error.
-
Create a requirements.txt for project dependencies.
pip freeze > requirements.txt -
Start creating apps!
python ./manage.py startapp my_appYour project folder will now look as follows
new_project/ new_project/ new_project/ # project-level items new_app/ __init__.py models.py tests.py views.py manage.pyAdd your app to
INSTALLED_APPSinsettings.pyINSTALLED_APPS = ( ... 'south', 'my_app', )Create and run a migration for your new app.
python ./manage.py schemamigration --initial new_app python ./manage.py migrate new_app