majdal
majdal

Reputation: 475

Django url templatetag (but not reverse() ) error: Caught NoReverseMatch while rendering

I'm trying to use the url template tag as such:

{% url all-labs-map %}

but when i view the page, i get this error:

Caught NoReverseMatch while rendering: Reverse for 'all-labs-map' with arguments '()' and keyword arguments '{}' not found.

When I use the template tag like this:

{% url gmaps.views.all_labs %}

It works just fine.

Here's the URL conf:

urlpatterns = patterns('gmaps.views',
    url(r'^lab_list/$', 'all_labs', name="all-labs-map" ),
)

I tried using the django shell to see if there was a problem with the named URL, but using

reverse('all-labs-map') 

returns the correct URL.

Any ideas on what's going on?

Thanks!

Majd

EDIT:

I am using django 1.2 on ubuntu with nginx server and gunicorn and virtualenv. I'm having another trouble with a custom tag where the library loads, but the tag itself is not recognized even though i'm using the correct tag registration syntax. Any ideas would be very greatly appreciated!

Upvotes: 9

Views: 1572

Answers (3)

Izkata
Izkata

Reputation: 9323

This is still high in Google results, but no one has answered it correctly yet. The key is this:

{% load url from future %}

Prior to Django 1.3, this was the syntax for the url templatetag:

{% url view_name arg1 %}

In Django 1.5, this will be the syntax:

{% url "view_name" arg1 %}

Starting in Django 1.3, the old version works but gives you a deprecation warning, telling you to {% load url from future %} and switch to the new version of that templatetag, in preparation for Django 1.5

Upvotes: 6

kgr
kgr

Reputation: 9948

Have you tried enclosing the name of the url in quotes like so:

{% url "all-labs-map" %}

or

{% url 'all-labs-map' %}

I've had some problems with URLs once and this seemed to help. Also regarding @user608133 comment - you need to restart gunicorn rather than nginx, as nginx is just a proxy...

Upvotes: 1

Michael Merchant
Michael Merchant

Reputation: 1508

This error might occur if you have another url with the same name overriding this one that requires multiple parameters. Is there any duplicates found when you do a search in your entire project for 'all-labs-map'?

Upvotes: 0

Related Questions