django의 로그인과 메일박스 수정 비밀번호 인증

5798 단어
urls.py
from django.urls import path, re_path, include
from django.contrib.auth.views import PasswordResetDoneView
from django.contrib.auth.views import LoginView
from django.contrib.auth.views import LogoutView
from django.contrib.auth.views import logout_then_login
from django.contrib.auth.views import PasswordResetConfirmView
from django.contrib.auth.views import PasswordResetCompleteView
from django.contrib.auth.views import PasswordResetView
from user import views

path('login/', LoginView.as_view(), name='login'),
path('logout/', LogoutView.as_view(), name='logout'),
path('logout_then_login/', logout_then_login, name='logout_then_login'),
# as_view
path('password-reset/', PasswordResetView.as_view(form_class=views.CustomPasswordChangeForm), name='password_reset'),
re_path(r'^password-reset/confirm/(?P[-\w]+)/(?P[-\w]+)/$', PasswordResetConfirmView.as_view(),
name='password_reset_confirm'),
path('password-reset/complete/', PasswordResetCompleteView.as_view(), name='password_reset_complete'),
path('password-reset/done/', PasswordResetDoneView.as_view(), name='password_reset_done'),

user.views.py

from django.contrib.auth.views import PasswordResetForm
from django.contrib.auth.models import User
from django.forms import ValidationError

# ,django , Form
class CustomPasswordChangeForm(PasswordResetForm):

def clean_email(self):
email = self.cleaned_data['email']
if User.objects.filter(email=email):
return email
else:
self.add_error('email',ValidationError(' '))

registration/password_reset_email.html
django
Someone asked for password reset for email {{ email }}. Follow the link below:
{{ protocol }}://{{ domain }}{% url "password_reset_confirm" uidb64=uid token=token %}
Your username, in case you've forgotten: {{ user.get_username }}

setting.py
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_SSL = True
EMAIL_HOST = 'smtp.qq.com'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'lgtbakuvoyfsbbjd'#qq SMTP
EMAIL_PORT = 465
EMAIL_FROM = ' <[email protected]>'
DEFAULT_FROM_EMAIL = EMAIL_FROM

from django.urls impost reverse_lazy # url app
LOGIN_REDIRECT_URL = reverse_lazy('account:dashboard')
LOGIN_URL = reverse_lazy('login')
LOGOUT_URL = reverse_lazy('logout')


전재 대상:https://www.cnblogs.com/louzi/p/10096663.html

좋은 웹페이지 즐겨찾기