Wamz
Wamz

Reputation: 151

Is it possible with Django to have a global view that is called on every page?

I was wondering if it is possible with Django to have a "global view" that is called on every page before all the initial views, for example to display additional information other than the user's information. All of this to avoid having to call a model on all of my views.

To allow me to call it only once.

Upvotes: 0

Views: 43

Answers (1)

Alexander Schillemans
Alexander Schillemans

Reputation: 581

Middleware allows you to execute code before the view gets processed: https://docs.djangoproject.com/en/dev/topics/http/middleware/#middleware

If you would like data to be available on every view, you can use context processors: https://docs.djangoproject.com/en/dev/ref/templates/api/#writing-your-own-context-processors

Upvotes: 1

Related Questions