Chapter 7. Advanced Views and URLconfs

In Chapter 2, Views and URLconfs, we explained the basics of Django's view functions and URLconfs. This chapter goes into more detail about advanced functionality in those two pieces of the framework.

URLconf Tips and Tricks

There's nothing special about URLconfs-like anything else in Django, they're just Python code. You can take advantage of this in several ways, as described in the sections that follow.

Streamlining function imports

Consider this URLconf, which builds on the example in Chapter 2, Views and URLconfs:

from django.conf.urls import include, url from django.contrib import admin from mysite.views import hello, current_datetime, hours_ahead urlpatterns = [ url(r'^admin/', include(, ...

Get Mastering Django: Core now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.