zoukankan      html  css  js  c++  java
  • 给自己项目添加注册、登陆、改密码、邮箱找回密码等功能,出现大坑!

    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
    

      

  • 相关阅读:
    双向绑定v-bind
    梁山好汉为何成不了大气候?(转)
    八大排序算法(转)
    在c或c+程序里打印调用栈。转
    cocos2dx 做test遇到一个问题,记录下来
    我所理解的cocos2dx自适配屏幕大小方案
    eclipse pydev 跳转
    mac 系统通用快捷键(mac 下的应用多数会往这些标准看齐)(转:http://yang3wei.github.io/blog/2013/02/08/chen-ni-yu-mac-chen-ni-yu-xcode/)
    使用cgitb来简化异常调试(记录下来,感觉很有用)
    python trackback的使用心得
  • 原文地址:https://www.cnblogs.com/tuobei/p/12507748.html
Copyright © 2011-2022 走看看