I am trying to use a template that contains a link such as this:
<a href="{% url search query,page.previous_page_number %}">previous</a>
I am trying to use it in multiple contexts; in other words, the URL alias “search” needs to point to a different target, depending on the view that renders the template.
Is there a way to pass such an alias to the template, such that the following (or similar) works?:
direct_to_template(request, 'my_template.html', {'search': my_url_alias})
As far as I know, you can’t, because, for a reason I do not understand, the
urltag does not take a string as input argument.What you have to do is to roll out your own template tag, based on the implementation of the
urltemplatetag in django, using a variable as a first argument.I use something like this (name it as you wish):