码迷,mamicode.com
首页 > 其他好文 > 详细

给自己项目添加注册、登陆、改密码、邮箱找回密码等功能,出现大坑!

时间:2020-03-16 23:33:11      阅读:86      评论:0      收藏:0      [点我收藏+]

标签:style   smtp   path   auth   log   time   inview   项目   eset   

1、使用django验证框架的登陆、注销功能,必须settings设置如下:

LOGIN_REDIRECT_URL = ‘shop:product_list‘
LOGOUT_REDIRECT_URL = ‘shop:product_list‘
LOGIN_URL = ‘shop:login‘
LOGOUT_URL = ‘shop:logout‘

LOGIN_REDIRECT_URL = ‘shop:product_list‘-----------登录成功后,转到哪个页面的url,在此设置。

LOGIN_URL = ‘shop:login‘-------------是用户重定向后实现登陆的url

2、修改密码、重置密码,如果想借用django自带框架,

path(‘password_change/‘,
         auth_views.PasswordChangeView.as_view(
            template_name=‘shop/password_change_form.html‘,
            success_url="/password_change/done/",
         ), name=‘password_change‘),
template_name必须重写为新的地址,success_url为下个path的url路径地址。
# _*_coding:utf-8_*_
# Author : rabbit
# Time   : 2020/3/15 22:43
# File   : urls.py
# IDE    : PyCharm

from django.urls import path
from django.contrib.auth import views as auth_views
from . import views

app_name = shop

urlpatterns = [
    path(login/, auth_views.LoginView.as_view(), name=login),
    path(logout/, auth_views.LogoutView.as_view(), name=logout),
    path(‘‘, views.product_list, name=product_list),
    # change password urls
    path(password_change/,
         auth_views.PasswordChangeView.as_view(
            template_name=shop/password_change_form.html,
            success_url="/password_change/done/",
         ), name=password_change),
    path(password_change/done/,
         auth_views.PasswordChangeDoneView.as_view(
            template_name=shop/password_change_done.html
         ), name=password_change_done),
    # reset password urls
    path(password-reset/,
         auth_views.PasswordResetView.as_view(
             template_name="shop/password_reset_form.html",
             email_template_name="shop/password_reset_email.html",
             subject_template_name="shop/password_reset_subject.txt",
             success_url="/password-reset-done/",
         ),
         name=password_reset),
    path(password-reset-done/,
         auth_views.PasswordResetDoneView.as_view(
             template_name="shop/password_reset_done.html"
         ),
         name=password_reset_done),
    path(password-reset-confirm/<uidb64>/<token>/,
         auth_views.PasswordResetConfirmView.as_view(
             template_name="shop/password_reset_confirm.html",
             success_url="/password-reset-complete/",
         ),
         name=password_reset_confirm),
    path(password-reset-complete/,
         auth_views.PasswordResetCompleteView.as_view(
             template_name="shop/password_reset_complete.html"
         ),
         name=password_reset_complete),
    path(register/, views.register, name=register),
    path(<slug:category_slug>/, views.product_list, name=product_list_by_category),
    path(<int:id>/<slug:slug>/, views.product_detail, name=product_detail),
]

 3、邮箱找回密码,必须settings添加如下代码:

EMAIL_HOST = ‘smtp.163.com‘
EMAIL_HOST_USER = ‘xxxxxx@163.com‘  # 填写你的邮件地址,用这个地址给(密码丢失的用户的注册邮箱)发找回密码邮件。
EMAIL_HOST_PASSWORD = ‘yyyyyyy‘  # 邮箱的smtp授权码
EMAIL_PORT = 25
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER

  

给自己项目添加注册、登陆、改密码、邮箱找回密码等功能,出现大坑!

标签:style   smtp   path   auth   log   time   inview   项目   eset   

原文地址:https://www.cnblogs.com/tuobei/p/12507748.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!