Django Cheat Sheet

This is a cheat sheet or minimal tutorial of django.

Preparing

sudo -H pip install django

And check django version is: python -m django --version

First step

start a django project by: django-admin startproject mysite
run the project by: python manage.py runserver
the default port is 8000, if want to run on a different port,
The command is: python manage.py runserver 8080

the command to create a app is: python manage.py startapps polls

Cheat sheet on apps

polls/views.py manage the view codes;
polls/urls.py manage the router codes
mysite/urls.py manage global router.

Cheat sheet on database

python manage.py migrate will apply database changes of apps registerd in INSTALLED_APPS, which defined in mysite/settings.py
python mangage.py makemigrations polls will notify django than the database of this app is changed.

Cheat seet on shell

python manage.py shell will preparing a shell environement of the django environment

Other

if want apps managed by the django backend, need to register it in apps/admin.py

0%