Question

I'm using Django CMS and am trying to figure out how to extend a view for a CMS page. For example, let's say I created a page called "About" in the CMS (/about) that is using the about_template.html file. Before I render the template I'd like to be able to send additional variables to the response. How do I overwrite the view to send these additional variables to the about page?

Était-ce utile?

La solution

This is done by adding variable to the context, like you can see here. A context is a simple dictionary, you just need to add some key-value in it so your template can read them.

context = {'books': Books.objets.all()}

You can also use class-based view, but you may want to learn the simple view before.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top