Reputation: 28302
In Django, inside a template, I do
{% url 'Customer.views.edit_customer' 1 %}
and I get a NoReverseMatch
exception. However, in the line before the template render I do:
print reverse('Customer.views.edit_customer', args=(1,))
and it prints the expected URL. I know I can always just pass in the result of reverse, but I would like to understand what's going on.
The url pattern is:
url(r'^customer/edit/(\d+)$', edit_customer),
Is there a way of doing the equivalent of the reverse call in the template?
Upvotes: 0
Views: 1595
Reputation: 10665
If you are using Django 1.4, remove the quotes
{% url Customer.views.edit_customer 1 %}
see https://stackoverflow.com/a/4981105/44816
Django 1.5 will accept quoted url matching patterns. You can load the url template tag from future, if you'd like to quote your patterns. Use the following before the first url tag in your templates
{% load url from future %}
Upvotes: 1
Reputation: 28302
The reason it didn't work the way I expected is because I forgot to put in:
{% load url from future %}
I had been using it in most of my templates, but forgot to add it to this one.
P.S. Thanks for the link to that question, it gave me the future answer.
Upvotes: 0