使用Django新增帳號管理功能

程式碼下載網址:https://github.com/jang0820/Django-MyWeb/tree/e960e6326b98c79fbf00c8710b26b108c64cb5e9

網站進行權限控管,需要帳號登入取得權限才能使用。

Step1)編輯myweb/myweb/urls.py,新增「path('accounts/', include('django.contrib.auth.urls')),」,啟用Django帳號管理功能。

Step2)新增樣板templates

參考https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/Authentication

\myweb\templates\registration\login.html

\myweb\templates\registration\logout.html

以下參考https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/Authentication

\myweb\templates\registration\password_reset_complete.html

\myweb\templates\registration\password_reset_confirm.html

\myweb\templates\registration\password_reset_email.html

\myweb\templates\registration\password_reset_form.html

\myweb\templates\registration\password_reset_form_done.html

Step3)編輯myweb\myweb\settings.py

新增「LOGIN_REDIRECT_URL = '/todo'」登入成功後,轉換到網址/todo

Step4)在命令提示字元模式,新增超級使用者

#python manage.py createsuperuser


Step5)連線http://127.0.0.1:8000/admin,使用超級使用者登入,新增一般使用者。