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_project
Start 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.py
for environment-specific settings (e.g. DB info, dev apps, etc...). Anything you place inlocal_settings.py
will only run locally.Add the following to the bottom of
settings.py
try: LOCAL_SETTINGS except NameError: try: from local_settings import * except ImportError: pass
Create a
local_settings.py
file in the same directory assettings.py
starting with the lines below. All dev specific go here.LOCAL_SETTINGS = True from settings import * DEBUG = True
-
Setup your databases.
Copy
DATABASES
fromsettings.py
intolocal_settings.py
and enter the information.DATABASES = { 'default': { ... } }
Add
south
toINSTALLED_APPS
insettings.py
INSTALLED_APPS = ( ... 'south', )
Perform a
syncdb
to create all of your initial datbaase tables.python ./manage.py syncdb
-
Run the development server to make sure everyone's happy
python ./manage.py runserver
You 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_app
Your 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.py
Add your app to
INSTALLED_APPS
insettings.py
INSTALLED_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