Defining "global variable" in Django templates
django, django-templates
Solution
If the URL is view specific, you could pass the URL from your view. If the URL needs to be truly global in your templates, you could put it in a context processor:
def object_url(request):
return {'object_url': reverse('myapp.views.dashboard')}
Problem
I'm doing something like: ``` {% extends 'base.html' %} {% url myapp.views.dashboard object as object_url %} {% block sidebar %} ... {{ object_url }} ... {% endblock %} {% block content %} ... {{ object_url }} ... {% endblock %} ``` Django documentation says url templatetag can define a variable in context, but I don't get any value for `object_url` in the following blocks. If I put the url templatetag at the beginning of each block, it works, but I don't want to "repeat myself". Anyone knows a better solution?