Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: cannot import name 'password_reset'

I am trying to do a password reset in django (2.1.1) but i keep getting the following error when i import password reset:

ImportError: cannot import name 'password_reset'

Thsis is my import:

from django.contrib.auth import (
    authenticate,
    get_user_model,
    login,
    logout,
    password_reset,
    password_reset_done
)
like image 396
Mphoza Avatar asked Oct 12 '18 08:10

Mphoza


1 Answers

The password_reset view, etc. function-based views have been rewritten to class-based views: the PasswordResetView [Django-doc] class in django-1.11, as is specified in the release notes. These function-based views could still be used, but were deprecated.

As of django-2.1, the function-based views have been removed, as specified in the release notes.

You can write it like:

from django.contrib.auth.views import PasswordResetView

from django.urls import path

urlpatterns = [
    path(
        'accounts/password_reset/',
        PasswordResetView.as_view(),
        name='password_reset'
    ),
]

of course you might want to change the URL, the view name, and pass parameters to the as_view to tailor the PasswordResetView to your specific use case.

Note that, as specified in the release notes, other related views have been removed as well, like password_change, password_change_done, password_reset_done, password_reset_confirm, and password_reset_complete.

like image 76
Willem Van Onsem Avatar answered Nov 01 '22 18:11

Willem Van Onsem