Cheatography
https://cheatography.com
https://docs.djangoproject.com/en/2.0/intro/tutorial01/
This is a draft cheat sheet. It is a work in progress and is not finished yet.
part 1
python -m django --version |
You can tell Django is installed and which version |
django-admin startproject mysite |
Creating a project |
python manage.py startapp polls |
Creating the Polls app |
url() argument: regex |
|
part 2
python manage.py migrate |
looks at the INSTALLED_APPS setting and creates any necessary database tables according to the database settings in your mysite/settings.py file and the database migrations shipped with the app (we’ll cover those later). You’ll see a message for each migration it applies. |
python manage.py makemigrations polls |
you’re telling Django that you’ve made some changes to your models (in this case, you’ve made new ones) and that you’d like the changes to be stored as a migration. |
python manage.py sqlmigrate polls 0001 |
The sqlmigrate command takes migration names and returns their SQL: |
python manage.py check |
this checks for any problems in your project without making migrations or touching the database. |
part 3
?P<pk> |
is a Python extension to the standard regex syntax. It means assign the results of this group (bounded by parens) to the variable name inside. In this case, assign the regex result to pk.https://teamtreehouse.com/community/help-me-understand-ppk |
The template system |
The template system uses dot-lookup syntax to access variable attributes. |
part 4
forloop.counter |
indicates how many times the for tag has gone through its loop |
except (KeyError, Choice.DoesNotExist) |
|
HttpResponseRedirect |
takes a single argument: the URL to which the user will be redirected# Always return an HttpResponseRedirect after successfully dealing # with POST data. This prevents data from being posted twice if a # user hits the Back button. |
|