Can't get password reset to work by following example
See original GitHub issueHi, I can’t get password reset to work. I’ve copied urls.py directly from the demo on GitHub:
# api/urls.py
from django.urls import include, path
from django.conf.urls import include, url
from django.contrib import admin
from django.views.generic import TemplateView, RedirectView
from django.contrib.auth.views import PasswordResetView, \
PasswordResetDoneView, PasswordResetConfirmView, PasswordResetCompleteView
urlpatterns = [
url(r'^$', TemplateView.as_view(template_name="home.html"), name='home'),
url(r'^signup/$', TemplateView.as_view(template_name="signup.html"),
name='signup'),
url(r'^email-verification/$',
TemplateView.as_view(template_name="email_verification.html"),
name='email-verification'),
url(r'^login/$', TemplateView.as_view(template_name="login.html"),
name='login'),
url(r'^logout/$', TemplateView.as_view(template_name="logout.html"),
name='logout'),
url(r'^password-reset/$',
TemplateView.as_view(template_name="password_reset.html"),
name='password-reset'),
url(r'^password-reset/confirm/$',
TemplateView.as_view(template_name="password_reset_confirm.html"),
name='password-reset-confirm'),
url(r'^user-details/$',
TemplateView.as_view(template_name="user_details.html"),
name='user-details'),
url(r'^password-change/$',
TemplateView.as_view(template_name="password_change.html"),
name='password-change'),
# this url is used to generate email content
url(r'^password-reset/confirm/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
TemplateView.as_view(template_name="password_reset_confirm.html"),
name='password_reset_confirm'),
url(r'^rest-auth/', include('rest_auth.urls')),
url(r'^rest-auth/registration/', include('rest_auth.registration.urls')),
url(r'^account/', include('allauth.urls')),
url(r'^admin/', admin.site.urls),
url(r'^accounts/profile/$', RedirectView.as_view(url='/', permanent=True), name='profile-redirect')
]
I’ve copied the Templates folder from the demo into my django project folder.
This is from my settings.py:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework.authtoken',
'rest_auth',
'django.contrib.sites',
'allauth',
'allauth.account',
'rest_auth.registration',
'api',
'users',
]
AUTH_USER_MODEL = 'users.CustomUser'
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
#
SITE_ID = 1
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
When I browse to the endpoint http://127.0.0.1:8000/api/v1/rest-auth/password/reset/ I see a form with this information and an input to type an email:
GET /api/v1/rest-auth/password/reset/
HTTP 405 Method Not Allowed
Allow: POST, OPTIONS
Content-Type: application/json
Vary: Accept
{
"detail": "Method \"GET\" not allowed."
}
If I enter an email address and click “Post” the page changes to show
{
"detail": "Password reset e-mail has been sent."
}
However no email text appears in the console.
Here’s the request that was sent, copied from the Network tab of the browser as cURL:
curl 'http://127.0.0.1:8000/api/v1/rest-auth/password/reset/' -H 'Cookie: tabstyle=html-tab; sessionid=n2nddatqzw71xiskvrn4kaynf2w6eq3x; csrftoken=ON4EIciQ7TawRpWH4g3qfh030tzHBnvQJFUZBxCMfQHn6xEgInj3ip5QCXX9r1HK' -H 'Origin: http://127.0.0.1:8000' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: en-GB,en-US;q=0.9,en;q=0.8' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36' -H 'Content-Type: multipart/form-data; boundary=----WebKitFormBoundarygXpeN1siqg1pdzU8' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8' -H 'Cache-Control: max-age=0' -H 'Referer: http://127.0.0.1:8000/api/v1/rest-auth/password/reset/' -H 'Connection: keep-alive' --data-binary $'------WebKitFormBoundarygXpeN1siqg1pdzU8\r\nContent-Disposition: form-data; name="csrfmiddlewaretoken"\r\n\r\nGFZOPWrxqc3lpAyBaycV8IFtAuxp3jfbBxP9IhLty9AcEIgaOFsybQKgcYVRTXr5\r\n------WebKitFormBoundarygXpeN1siqg1pdzU8\r\nContent-Disposition: form-data; name="email"\r\n\r\nmy_name@adomain.com\r\n------WebKitFormBoundarygXpeN1siqg1pdzU8--\r\n' --compressed
If I paste that into a terminal, I get back the html for the password reset page.
Please, can you explain what I am missing to get this basic feature working?
Thank you.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:8
Top GitHub Comments
Yes, use your custom user model.
Check the actual email backend:
You can also test it in the console:
Thank you for your reply. I’ve got it working in in the end by changing a lot of things, so I can’t really retest this. But I wonder if the demo code is out of date? Maybe rest-framework has changed?