Reputation: 331
I'm encountering an odd problem with namespaced url in Django, and I cannot find what I am doing wrong while it is working on simpler examples and using the
Basically, my project is made of two apps, user and model. In my general urls.py, I defined :
url(r'^model/', include('model.urls', namespace="model")),
url(r'^user/', include('user.urls', namespace="user")),
In the user.urls.py file, I defined the following url:
url(r'^duo/(?P<pseudo>[a-z]+)/$',views.duo, name='duo'),
The duo view is rather simple :
def duo(request,pseudo):
print pseudo
return render(request,"user/duo.html",locals())
Therefore, when I use in my templates:
{% url 'user:duo' lena %}
I expect the url to be resolved as /user/duo/lena. Instead, I got the following NoReverseMatch:
Reverse for 'duo' with arguments '('',)' and keyword arguments '{}' not found. 1 pattern(s) tried: [u'user/duo/(?P<pseudo>[a-z]+)/$']
I take any guess to fix my mistake !
Upvotes: 2
Views: 212
Reputation: 8821
Edited according to the dicussion: You need to quote your paramater. Also keyword parameters might make things clearer:
{% url 'user:duo' pseudo='lena' %}
If you don't quote the value, Django assumes this is a context variable and as lena
is not a context variable in your case this evaluates to None
. The error actually tells you, you didn't provide args or kwargs for the reverse lookup.
Upvotes: 0