NoReverseMatch: Reverse with arguments and keyword arguments '{}' not found. 0 pattern(s) tried: []
July 10, 2016, 3:47 a.m.
Periodically, I get next error:
NoReverseMatch: Reverse for 'my_url_name' with arguments '(u'...',)' and keyword arguments '{}' not found. 0 pattern(s) tried: []
I do not understand quickly why my code is not works. Well, I write down this notes. Check list:
1. Include urls.py of app to project urls.py
urlpatterns = patterns('', ... url(r'^my_app/', include('my_app.urls')), ... )
2. Include url to urls.py of app:
urlpatterns = patterns('', url(r'^my-url-name/(?P<my_object_id>\d+)/$', my_app.views.my_view, name='my_url_name'), )
3. Add required arguments to urls.py
urlpatterns = patterns('', url(r'^my-url-name/(?P<my_object_id>\d+)/$', my_app.views.my_view, name='my_url_name'), )
4. Add required arguments with call 'url' function in template or 'reverse' function in python code
# in template.html <a href="{% url 'my_url_name' my_object_id %}">Do something</a> # in python code reverse('my_url_name', args=(my_object_id, ))
If your view doesn't provide arguments (such as my_object_id), then check the first two steps only.
Comments: 0