Learning About Django
Documentation
Project Creation
django-admin.py startproject <projectname>
cd <projectname>
django-admin.py startapp <appname>
python manage.py runserver
# Edit settings.py
DATABASE_ENGINE = 'sqlite3'
DATABASE_NAME = '<path to database file>'
TIME_ZONE = '<Region>/<City>'
- Initialise database and set up admin user
python manage.py syncdb
- Add the application to the site:
# Edit settings.py
INSTALLED_APPS = (....)
- Re-run python manage.py syncdb after modifying fields in models.py but be aware some changes may require deleting existing tables.
- TODO: Add admin setup instructions
Use Django ORM to generate table creation SQL
- Set up directory and files
## With directory layout:
settings.py
orm/
__init__.py
models.py
## With content:
# settings.py
DATABASE_ENGINE="sqlite3"
DATABASE_NAME="database_name.db"
INSTALLED_APPS = ('orm')
# models.py
from django.db import models
class SomeModel(models.Model):
...
- Run command from directory containing settings.py and orm directory (this will generate SQL):
django-admin.py sqlall --settings=settings --pythonpath=. orm
- Or run this command to actually create the database:
django-admin.py syncdb --settings=settings --pythonpath=.