This seems like a common problem people are running into, but I can't figure it out for the life of me. I've set up a URL:
from django.conf.urls import url
from . import views
from django.contrib.auth import views as auth_views
urlpatterns = [
url(r'^login/$', views.login_view, name='login'),
url(r'^password_reset/$', auth_views.password_reset, name='password_reset'),
url(r'^password_reset_done/$', auth_views.password_reset_done, name='password_reset_done'),
url(r'^auth/$', views.login_auth, name='login_auth'),
url(r'^register/$', views.register_user, name='register'),
url(r'^logout/$', views.logout_user, name='logout'),
]
I try to link to the password_reset URL:
Forgot Password?
But it gives me the following error:
NoReverseMatch at /accounts/password_reset/
Reverse for 'password_reset_done' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
This seems like a really simple bit of code, but it doesn't work. I can successfully call password_reset_done using this exact method, but for some reason it doesn't work with password_reset.
The password_reset line should look like this:
url(r'^password_reset/$', auth_views.password_reset, {'post_reset_redirect' : '/accounts/password_reset_done/'}, name='password_reset'),
Related
So, I am writing code with Python and Django (and other web dev requirements).
from django.urls import path
from . import views
urlpatterns = [
path("", views.index, name="index"),
path('wiki/<str:name>/', views.info, name="info"),
path("create", views.create, name="create"),
path("results", views.search, name="search"),
path("wiki/<str:name>/edit", views.edit, name="edit")
]
The problem I am facing is that in path("wiki/<str:name>/edit", views.edit, name="edit"), I get an error:
NoReverseMatch at /wiki/Django/>
Reverse for 'edit' with no arguments not found. 1 pattern(s) tried: ['wiki/(?P[^/]+)/edit$']>
And I want to refer to the url in path('wiki/<str:name>/', views.info, name="info")
Please help me fix the error
I have a problem with django's view "password_reset_done".
When I try to open accounts/reset-password I have this error.
But if I open url accounts/reset-password/done it works.
URLS.PY of "accounts" app
from django.conf.urls import url
from django.contrib.auth.views import login , logout, password_reset,
password_reset_done
from . import views
urlpatterns = [
url(r'^register/$', views.register, name='register'),
url(r'^profile/$', views.profile, name='profile'),
url(r'^profile/prpage/(\d+)/$', views.profile, name='prpage'),
url(r'^profile-edit/$', views.profiledit, name='profile-edit'),
url(r'^login/$', login ,{'template_name':'accounts/login.html'},
name='login'),
url(r'^logout/$', views.logout_view, name='logout'),
url(r'^profile/(?P<proj_id>\d+)/$', views.userprojectpage,
name='userprojectpage'),
url(r'^changepassword/$', views.changepassword, name='changepassword'),
url(r'^reset-password/$', password_reset, name='reset_password'),
url(r'^reset-password/done/$', password_reset_done,
name='password_reset_done'),
]
please help! Thanks in advance)
Add success_url parameter of Class Based View PasswordResetView. This will replace default route of password_reset_done
from django.urls import path, re_path, include, reverse_lazy
path('reset/',PasswordResetView.as_view(
template_name='password_reset.html',
email_template_name='password_reset_email.html',
subject_template_name='password_reset_subject.txt',
...
success_url = reverse_lazy('accounts:password_reset_done')
...
...
),name='password_reset'),
11 there are some change made look like password_reset, password_reset_done not able to import therefore display this error regarding this url https://github.com/django/django/blob/stable/1.11.x/django/contrib/auth/views.py.
There are two way to resolve the error above.
to resolve this error add url(r'', include('django.contrib.auth.urls')), to main urls.py in your project. This will stopped the error and keep your urls in your accounts:
url(r'^reset-password/$', password_reset, name='reset_password'),
url(r'^reset-password/done/$', password_reset_done,
name='password_reset_done'),
I have resolved this error like above and it works fine.
Second way to resolve the error is different than first option above,remove the url(r'', include('django.contrib.auth.urls')), from main urls.py file and in your accounts/urls.py add following url's:
url(r'^reset-password/$', password_reset,
{'template_name':'reset_password.html',
'post_reset_redirect':'accounts:password_reset_done',
'email_template_name': 'reset_password_email.html'},
name='reset_password'),
url(r'^reset-password/done/$', password_reset_done,
{'template_name': 'reset_password_done.html'}, name='password_reset_done'),
url(r'^reset-password/confirm/(?P[0-9A-Za-z]+)-(?P.+)/$',
password_reset_confirm, {'template_name': 'reset_password_confirm.html',
'post_reset_redirect':'accounts:password_reset_complete'},
name='password_reset_confirm'),
This is the second solution and working.
I hope that helps your problem and sorry for delay respond your last comment, I was away.
DilMac
I am using Django version 1.10.7. Currently in my html I have:
</span>
My project urls.py has
from django.conf.urls import include,url
from django.contrib import admin
from base import views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^team/', include('team.urls'), name='team'),
url(r'^game/', include('game.urls'), name='game'),
url(r'^about/', include('base.urls'), name='about'),
url(r'^$', views.home, name='home'),
]
And in views.py,
from django.shortcuts import render
# Create your views here.
def about(request):
return render(request,'base/about.html',{})
def home(request):
return render(request,'base/home.html',{})
This gives the error:
NoReverseMatch at /
Reverse for 'home' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.10.7
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'home' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
How can I fix this?
Try to put your urls in this order:
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', views.home, name='home'),
url(r'^team/', include('team.urls'), name='team'),
url(r'^game/', include('game.urls'), name='game'),
url(r'^about/', include('base.urls'), name='about'),
]
if works, it means that there is a problem in your other included urls files.
Even after mentioning the name='password_reset_done', getting the NoReverseMatch error for 'password_reset_done'.
below is the urls.py file of blog application.
from django.conf.urls import url
from . import views
from django.contrib.auth.views import password_reset, password_reset_done
urlpatterns = [
url(r'^$', views.post_list, name='post_list'),
url(r'^login/$', views.user_login, name='user_login'),
url(r'^logout/$', views.user_logout, name='user_logout'),
url(r'^reset-password/$', password_reset, name='password_reset'),
url(r'^reset-password/done/$', password_reset_done, name='password_reset_done'),
url(r'^(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/(?P<slug>[\w-]+)/$', views.post_detail, name='post_detail'),
url(r'^(?P<post_id>\d+)/share/$', views.post_share, name='post_share'),
url(r'^(?P<tag_slug>[\w-]+)/$', views.post_list, name='post_list_by_tag'),
]
Please help!!!
Make following changes in main's urls.py:
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^blog/', include('blog.urls')),
]
Make following changes in blog's urls.py:
from django.contrib.auth import views as auth_views
urlpatterns = [
url('^reset-password/$', auth_views.password_reset),
url('^reset-password/done/$', auth_views.password_reset_done),
]
add 'password_reset_done' name to urls.py:
from django.contrib.auth import views as auth_views
urlpatterns = [
url('^reset-password/$', auth_views.password_reset),
url('^reset-password/done/$', auth_views.password_reset_done, name='password_reset_done'), ]
NoReverseMatch at /myapp/reset-password/
Reverse for 'password_reset_done' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
Request Method: GET
Request URL: http://127.0.0.1:8000/myapp/reset-password/
Django Version: 1.10.5
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'password_reset_done' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
Exception Location: C:\Python35-32\lib\site-packages\django\urls\resolvers.py in _reverse_with_prefix, line 392
Python Executable: C:\Python35-32\python.exe
Python Version: 3.5.3
Python Path:
['c:\Workarea\projects\Learning\dJango\mysite',
'C:\Python35-32\lib\site-packages\requests_ftp-0.3.1-py3.5.egg',
'C:\Python35-32\python35.zip',
'C:\Python35-32\DLLs',
'C:\Python35-32\lib',
'C:\Python35-32',
'C:\Python35-32\lib\site-packages']
Server time: Mon, 10 Apr 2017 10:10:32 +0000
I just installed the Django-Registration app and I have everything working except I can not figure out the password reset methods. Whenever I navigate to accounts/password/reset/ I get the following error:
Reverse for 'password_reset_done' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
Any ideas? Is there some problems with the django-registration urls?
Update:
I have added the following lines of code from a previous post here: Django 1.6 and django-registration: built-in authentication views not picked up
into my registration/backends/default/urls.py
url(r'^password/change/$',
auth_views.password_change,
name='password_change'),
url(r'^password/change/done/$',
auth_views.password_change_done,
name='password_change_done'),
url(r'^password/reset/$',
auth_views.password_reset,
name='password_reset'),
url(r'^password/reset/done/$',
auth_views.password_reset_done,
name='password_reset_done'),
url(r'^password/reset/complete/$',
auth_views.password_reset_complete,
name='password_reset_complete'),
url(r'^password/reset/confirm/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$',
auth_views.password_reset_confirm,
name='password_reset_confirm'),
#and now add the registration urls
url(r'', include('registration.backends.default.urls')),
and then I added the following import:
from django.contrib.auth import views as auth_views
But then when I run the program after my server restart I get the following error message:
Exception Type: RuntimeError Exception Value: maximum recursion depth
exceeded while calling a Python object Exception Location:
/home/ubuntu/django-skippl/local/lib/python2.7/site-packages/Django-1.6.2-
py2.7.egg/django/utils/datastructures.py in init, line 287 Python
Executable: /home/ubuntu/django-skippl/bin/python
try this urls.py
import os
from django.contrib.auth import views as auth_views
from django.conf.urls import patterns, include, url
from django.conf import settings
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^accounts/', include('registration.backends.default.urls')),
#override the default urls
url(r'^password/change/$',
auth_views.password_change,
name='password_change'),
url(r'^password/change/done/$',
auth_views.password_change_done,
name='password_change_done'),
url(r'^password/reset/$',
auth_views.password_reset,
name='password_reset'),
url(r'^password/reset/done/$',
auth_views.password_reset_done,
name='password_reset_done'),
url(r'^password/reset/complete/$',
auth_views.password_reset_complete,
name='password_reset_complete'),
url(r'^password/reset/confirm/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$',
auth_views.password_reset_confirm,
name='password_reset_confirm'),
url(r'^admin/', include(admin.site.urls)),
)
This is should work :
url(r'^accounts/', include('registration.backends.simple.urls')),
url(r'^accounts/password/reset/done/$', 'django.contrib.auth.views.password_reset_done',
name='password_reset_done'),