Taking notes.
django-admin startproject mysite
python manage.py startapp <app-name>
- Views and urls.
-
settings.py
: Set timezone -
Database usage:
python manage.py migrate
- Models Fields
settings.py
plug apps inINSTALLED_APPS
variable.
makemigrations
command.sqlmigrate
commandmigrate
command.
python manage.py shell
Suppose a polls
app and a Question
model, on polls/admin.py
file add:
from .models import Question
admin.site.register(Question)
That's it.
- Queries, get, filters.`
- New views on new urls.
- Templates. Read more here.
- Raising 404 error
raise django.http.Http404("Some message")
- Shortcuts:
get_object_or_404()
andget_list_or_404()
- Removing hardcoded URLs in templates, e.g:
<a href="{% url 'detail' question.id %}">{{ question.question_text }}</a>
- Define app namespaces with
app_name
inurls.py
.
- Simple forms
- Generic Views
ListView
andDetailView
classes- Documentation