Tutorial by Examples

Example for a functional view to create an object. Excluding comments and blank lines, we need 15 lines of code: # imports from django.shortcuts import render_to_response from django.http import HttpResponseRedirect from .models import SampleObject from .forms import SampleObjectForm # vie...
The above example only works if your tasks are entirely standard tasks. You do not add extra context here, for example. Let's make a more realistic example. Assume we want to add a page title to the template. In the functional view, this would work like this - with just one additional line: def cr...
The true power of generic views unfolds when you combine them with Mixins. A mixin is a just another class defined by you whose methods can be inherited by your view class. Assume you want every view to show the additional variable 'page_title' in the template. Instead of overriding the get_context...

Page 1 of 1