Django Generic Class Based View Tip

Those reading this via a feed reader will have to view the page on my blog as I am using embedded gists. I’ll find a solution for that in the future.

So say you have a base template that looks something like:

And a template that looks like either of these:

It used to be that you could write something like this:

But generic function based views are deprecated and the world is being strongly urged to move to generic class based views. If you would like to get extra_content working with the direct_to_template replacement TemplateView, you can use a view like the following:

And a urls.py like the following using it:

The code used in this blog post can be found in this gist.

One thought on “Django Generic Class Based View Tip

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s