This page provides some good Django resources.
Good posts about Django
-
Don’t repeat Yourself – Understanding Django Template Inheritance
Don’t repeat Yourself – Understanding Django Template Inheritance [April 17, 2018 by Daniel Hepper, PDF]
-
Django is too complicated!
Django is too complicated! [August 14, 2018 by Daniel Hepper]
Good posts about Django updates
-
Django 2.0 url() to path() cheatsheet
Django 2.0 url() to path() cheatsheet [May 2, 2018 by Daniel Hepper, PDF]
Django 2.0 introduced a new way to define URLs, which greatly simplifies how parameters are captured.
In earlier versions of Django, you had to use the url()
method and pass a regular expressions with named capturing groups to capture URL parameters.
In Django 2.0, you use the path()
method with path converters to capture URL parameters.
path()
always matches the complete path, so path('account/login/')
is equivalent to url('^account/login/$')
.
use re_path()
, which is a drop-in replacement for the old url()
method.
from django.urls import re_path
...
re_path(r'^.*', TemplateView.as_view(template_name = "home.html")),
Also, the newpath()
method does not support positional arguments, you must provide a name.
So, assuming the argument to your view is called id
(something like def detail(request, id)
), your URL definition would look like this:
path('', views.detail, name=’detail’)
Alternatively, you could just use re_path()
instead of url()
:
re_path(r’^[0-9]+)$’, views.detail, name=’detail’)
Don’t repeat Yourself – Understanding Django Template Inheritance
References and Reading List
- Considerate Code – Category: Django