Sunday, July 28, 2019

Re: How to set (global) context value from a templatetag?



from django.template import RequestContext; rc = RequestContext(request)

rc contains all the context that had been passed on to TemplateResponse within the view, o I want to add few more there from the template tag and just cant figure out how.

Thanks a lot for any ideas!

First thing that comes to mind:



If you'll be using these same variables in a majority of your templates, then I'd recommend looking at a custom template context processor:


That way you can define constants in you application code and have them automatically pulled in as template variables in all your templates without having to repeat a template tag in every template.

-James

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciVc6t6NCVgHOGX_WUpgBnkVe%2BtxF-8gG6-i5Ou-G_4Rbg%40mail.gmail.com.

No comments:

Post a Comment