Book Image

Django 1.0 Template Development

Book Image

Django 1.0 Template Development

Overview of this book

Table of Contents (17 chapters)
Django 1.0 Template Development
Credits
About the Author
About the Reviewers
Preface
Index

Context processors


In the course of your Django development you may have data that you want to make available to your Context without having to specify it in every view. This could be things such as information about the current authenticated user, media settings, or a custom piece of data that you need in all of your templates. If you find yourself adding the same items to your Context in many views, it's a good candidate for a context processor.

Exploring the default context processors

Django provides us a set of libraries for commonly used context processors. These include auth, debug, i18n, and media. Each of these libraries adds extra variables to our context that we can use from within our templates.

Auth

Auth adds the variables user, messages, and perms to the context. user is the currently logged in user, messages is a list of messages for that user (you see this a lot in the admin app when you change something—it's the message at the top of the screen after you add/save/delete)...