Django url tag multiple parameters


I have two similar codes. The first one works as expected.

urlpatterns = patterns('',
                       (r'^(?P<n1>\d)/test/', test),
                       (r'', test2),
{% url testapp.views.test n1=5 %}

But adding the second parameter makes the result return empty string.

urlpatterns = patterns('',
                           (r'^(?P<n1>\d)/test(?P<n2>\d)/', test),
                           (r'', test2),)

{% url testapp.views.test n1=5, n2=2 %}

Views signature:

def test(request, n1, n2=1):
4/4/2010 8:11:46 PM

Accepted Answer


{% url testapp.views.test n1=5,n2=2 %}

without the space between the arguments

Update: As of Django 1.9 (and maybe earlier) the correct way is to omit the comma and separate arguments using spaces:

{% url testapp.views.test n1=5 n2=2 %}
8/13/2016 8:24:31 AM

From Django 1.5 Warning Don’t forget to put quotes around the function path or pattern name!

{% url 'some-url-name' arg1=v1 arg2=v2 %}

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow