Reception error: reverse value for arguments '()' and keyword arguments not found

I am getting an error creating a link in my Django template.

My template looks like this:

<a href="{% url 'location_detail' pk=location.id %}">{{ location.name }}</a> 

My urls.py looks like this:

 url(r'^location(?P<pk>\d+)/$', views.location_detail, name="location_detail"), 

My view looks like this:

 def location_detail(request, pk=None): 

I get an error message:

 Reverse for views.location_detail with arguments '()' and keyword arguments '{u'pk': 1L}' not found. 

I am using Django 1.5 and python 2.7.2

Thanks!

+4
source share
2 answers

The problem was that I had a namespace in the main urls.py project:

 url(r'^com/', include('com.urls', namespace="com")), 

URL change:

 {% url 'com:location_detail' pk=location.id %} 

It's a trick

+10
source

You specified your name url pattern, so you should use this name in the call {% url %} :

 {% url 'location_detail' pk=location.id %} 
+3
source

Source: https://habr.com/ru/post/1493030/


All Articles