I'm following the "Tango with Django" tutorial and one of the chapters is about using Registration View Redux to deal with user authentication. Everything works except for when I register a new user. The user actually gets added just fine. But after submitting it, instead of being redirected to the "registration complete" page, I get this error:
NoReverseMatch at /accounts/register/
Reverse for 'registration' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
Request Method: POST
Request URL: http://192.168.2.10:5555/accounts/register/
Django Version: 1.7
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'registration' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
Exception Location: C:\Python34\Lib\site-packages\django\core\urlresolvers.py in _reverse_with_prefix, line 463
Python Executable: C:\Python34\python.exe
Python Version: 3.4.2
Python Path:
['D:\\_python_projects\\tango_with_django_project',
'C:\\Python34\\Lib\\site-packages\\setuptools-8.2.1-py3.4.egg',
'C:\\Python34\\lib\\site-packages\\setuptools-8.2.1-py3.4.egg',
'C:\\Python34\\Lib\\site-packages',
'C:\\Windows\\system32\\python34.zip',
'C:\\Python34\\DLLs',
'C:\\Python34\\lib',
'C:\\Python34']
Server time: Sat, 27 Dec 2014 21:04:15 -0500
Traceback:
Environment:
Request Method: POST
Request URL: http://192.168.2.10:5555/accounts/register/
Django Version: 1.7
Python Version: 3.4.2
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rango',
'registration')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
Traceback:
File "C:\Python34\Lib\site-packages\django\core\handlers\base.py" in get_response
111. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Python34\Lib\site-packages\django\views\generic\base.py" in view
69. return self.dispatch(request, *args, **kwargs)
File "C:\Python34\Lib\site-packages\registration\views.py" in dispatch
79. return super(RegistrationView, self).dispatch(request, *args, **kwargs)
File "C:\Python34\Lib\site-packages\django\views\generic\base.py" in dispatch
87. return handler(request, *args, **kwargs)
File "C:\Python34\Lib\site-packages\registration\views.py" in post
35. return self.form_valid(request, form)
File "C:\Python34\Lib\site-packages\registration\views.py" in form_valid
90. return redirect(to, *args, **kwargs)
File "C:\Python34\Lib\site-packages\django\shortcuts.py" in redirect
74. return redirect_class(resolve_url(to, *args, **kwargs))
File "C:\Python34\Lib\site-packages\django\shortcuts.py" in resolve_url
158. return urlresolvers.reverse(to, args=args, kwargs=kwargs)
File "C:\Python34\Lib\site-packages\django\core\urlresolvers.py" in reverse
546. return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
File "C:\Python34\Lib\site-packages\django\core\urlresolvers.py" in _reverse_with_prefix
463. (lookup_view_s, args, kwargs, len(patterns), patterns))
Exception Type: NoReverseMatch at /accounts/register/
Exception Value: Reverse for 'registration' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
My template for the registration form:
{% extends "rango/base.html" %}
{% block title %}Register{% endblock %}
{% block body_block %}
<h1>Register to Rango</h1>
<form method="post" action=".">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Submit" />
</form>
{% endblock %}
urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
from django.conf import settings
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'tango_with_django_project.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^accounts/', include('registration.backends.simple.urls', namespace='registration')),
url(r'', include('rango.urls', namespace='rango')),
)
Any ideas?
You'll need to alter your urls.py file to add in a class that extends the default RegistrationView:
from registration.backends.simple.views import RegistrationView
class MyRegistrationView(RegistrationView):
def get_success_url(self, request, user):
return '/rango/'
And then update your url pattern so that it looks like this:
url(r'^accounts/register/$', MyRegistrationView.as_view(), name='registration_register')
I hope this helps.
I tried to use namespacing while going through the book, but I've encountered this error too. Removing namespace='registration'
from project's urls.py and altering from {% url 'registration:REGISTRATION_VIEW_NAME' %}
to {% url 'REGISTRATION_VIEW_NAME' %}
in all templates have resolved the issue. Now everything is working fine.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.