kumarpapunjay

Posted 18-Sep-2020 | 1153 | Javascript

What is a NoReverseMatch error in Django?

I am using Django to build a website and when I run the server, it throws an exception NoReverseMatch:

NoReverseMatch at /blog/ Reverse for 'blog_name' with arguments '()' and keyword arguments '{}' not found. n pattern(s) tried: []

How to fix it?

Replies

Juvienelle

Posted 09-May-2024

I was stuck into the same issue a few days back. You need to take a look inside the urls file and check the path with name blog_name and the method that triggers when you visit this path. Also, make sure you check the template where you have used the url name. Hope that helps.

ritusoni

Posted 09-May-2024

The NoReverseMatch error in Django occurs when the application can not find a matching url pattern for the url you've provided in your project's installed app's urls.

URL resolver exceptions are defined in django.urls. It has 2 exceptions Resolver404 and NoReverseMatch.

NoReverseMatch: The NoReverseMatch exception is raised by django.urls when a matching URL in your URLconf cannot be identified based on the parameters supplied.

Steps to follow:

  • Start with the error message you are getting

NoReverseMatch at /blog/

  • This means it is the url that the server is trying to access but it contains a url that cannot be matched

Reverse for 'blog_name'

  • So blog_name is the name of the url that your Django application cannot find

with arguments '()' and

  • Here are the non-keyword arguments the error message is providing to the url

keyword arguments '{}' not found.

  • Here are the keyword arguments its providing to the url

n pattern(s) tried: []

  • The application has tried to match against the patterns it found by following your urls.py files

How to debug: Start looking for code in your source code which is relevant to the url that is currently being rendered and also checks the templates, views, and urls related to it. Don't forget to check the part of the code that you are currently developing. As most of the times, the error can be found there.

Once you find the block of code. Fix that and save, now the application will restart automatically and now try to run it.