0

How can I make a django queryset persistent across all my templates?

For example: I want a list of all users to be available on every template no matter if I call the queryset or not in each template view.

Right now I'm doing this on every single view of my app:

users = User.objects.values_list('first_name','id')
users_json = simplejson.dumps(list(users), cls=DjangoJSONEncoder)

There must be a better way:

Gustavo Reyes
  • 1,313
  • 1
  • 17
  • 31
  • This is what [context processors](https://docs.djangoproject.com/en/1.7/ref/templates/api/#subclassing-context-requestcontext) are for. – Daniel Roseman Mar 18 '15 at 15:28
  • Thanks for pointing me in the right direction there's also an example for contex processors in this question: http://stackoverflow.com/questions/2893724/creating-my-own-context-processor-in-django – Gustavo Reyes Mar 18 '15 at 16:20

0 Answers0