How to debug Django NoReverseMatch errors?

People, I get a NoReverseMatch error for a specific URL request.

I would like to know: are there any good debugging tools in general? For example, how can I register, which URLs are registered?

My specific example:

Template:

<a href= "{% url django.contrib.auth.views.redirect_to_login blarg %}">log in</a> 

Error:

 NoReverseMatch: Reverse for 'settings.django.contrib.auth.views.redirect_to_login' with arguments '('[[ UNDEFINED VARIABLE ]]',)' and keyword arguments '{}' not found. 

I use the Google App Engine with appenginepatch, so Django itself has changed.

+4
source share
1 answer

In this particular case, when the URL call uses the full path to the view function, it is easy to do this simply by looking at the view function. In Django-1.1, it looks like this:

 def redirect_to_login(next, login_url=None, redirect_field_name=REDIRECT_FIELD_NAME): "Redirects the user to the login page, passing the given 'next' page" if not login_url: login_url = settings.LOGIN_URL return HttpResponseRedirect('%s?%s=%s' % (login_url, urlquote(redirect_field_name), urlquote(next))) 

This function does not even accept the request object, so in fact it is not even the right kind, and it is not even registered in django/contrib/auth/urls.py This means that it is probably intended only for use as an auxiliary function in other representations.

In any case, based on your specific example, what you probably wanted to do was use the plain old login url:

 <a href="{% url django.contrib.auth.views.login %}?next={{request.path}}"> log in </a> 

In addition, I believe that if you set TEMPLATE_DEBUG = True to your settings, you will get a list of all the url templates that django checked before throwing an error.

+3
source

All Articles