NoReverseMatch: Reverse with arguments and keyword arguments '{}' not found. 0 pattern(s) tried: []

July 9, 2016, 11:47 p.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.

Rate this article

0 from 5 (total 0 ratings)

You can send feedback, suggestions or comments on this article using this form:

Fields marked by star ( * ) is required.

Thank you for yor feedback!

Author of Article

The right to use content on this page http://vivazzi.ru/en/it/reverse-not-found/:

Permission is granted to copy an content with its author and reference to the original without using the parameter rel="nofollow" in tag <a>. Usage:

Author of Article: Maltsev Artem
Link to article: <a href="http://vivazzi.ru/en/it/reverse-not-found/">http://vivazzi.ru/en/it/reverse-not-found/</a>

More: Terms of site usage

Comments: 0

You can leave a comment as an unregistered user. But by registering, you will be able to receive notifications of replies, and also have access to your personal account to view your comments.

To comment in one's own name you should log in or sign up in the usual way or through social networks:

Send

There is no search on this site, so I offer to use usual search engine, for example, Google, adding "vivazzi" after your request.

Try it