Reputation: 11118
I have a URL conf such as this:
url(r'^value-toggle/(?P<profile_id>\d{1,10})/(?P<on_or_off>on|off)/$',
'clipfo.profile.views.value_toggle',
name='value-toggle'),
In my template, I am trying to link to it:
<a href="{% url value-toggle profile_id=profile.id on_or_off='off' %}">Turn off</a>.
I get the following error when viewing the page which contains the url tag:
Caught NoReverseMatch while rendering: Reverse for 'value-toggle' with arguments '()' and keyword arguments '{'profile_id': 5, 'on_or_off': '### FIX ME - bad template variable ###'}' not found.
Please note that "### FIX ME - bad template variable ###" is my TEMPLATE_STRING_IF_INVALID
value.
How can i pass a literal "off" as the value of named param on_or_off
to the url
django template tag?
Upvotes: 0
Views: 2411
Reputation: 11118
The future has saved me!
Just called
{% load url from future %}
at the beginning of my template.
Using the url tag from future allowed me to do what I needed to do. I only had to wrap the name of the url in single quotes, such as:
<a href="{% url 'value-toggle' profile_id=profile.id on_or_off='off' %}">Turn off</a>.
Upvotes: 2