Django context processor made available without a view

177 Views Asked by At

I want to query all products and load them in a dict with category-id as key using a context processor. Then I want to make this dict available in a template, in order to send it to a template tag as argument.

Is it possible to use the context without a view? Your help is appreciated.

2

There are 2 best solutions below

1
On

Context processors have nothing to do with views. They are run every time you create a RequestContext, which you often do as part of render_to_response but can certainly do outside of that.

1
On

Why "make the dict available in a template to send it to a template tag" when you can just load your products from the templatetag's code itself ?

wrt/ RequestContext, it's a very ordinary python class and there's no special magic involved: you just have to import the class and instanciate it.