开发者

How can I have specific information passed along each time a view is rendered in Django?

开发者 https://www.devze.com 2023-02-19 05:41 出处:网络
I\'m building a web site in Django, and I want to have some basic information added to the dictionary that is passed to the template renderer. For now, I\'m just wanting a list of the static pages in

I'm building a web site in Django, and I want to have some basic information added to the dictionary that is passed to the template renderer. For now, I'm just wanting a list of the static pages in my site so that I can put links in the header, but would like to be able to exp开发者_JS百科and that information later.


Context Processors

http://docs.djangoproject.com/en/dev/ref/templates/api/#writing-your-own-context-processors

It's just a function that takes 1 argument, request, and returns a dictionary. Specify active processors in your settings file.

def MyProcessor(request):
     return {'im_available_in_every_template': 'that uses RequestContext'}

Oh, note that this only works on views that use RequestContext -- I just haven't not used RequestContext in 3 years I keep forgetting to mention it.

0

精彩评论

暂无评论...
验证码 换一张
取 消