官术网_书友最值得收藏!

Using Django authentication views

Django includes several forms and views in the authentication framework that you can use straight away. The login view you have created is a good exercise to understand the process of user authentication in Django. However, you can use the default Django authentication views in most cases.

Django provides the following class-based views to deal with authentication. All of them are located in django.contrib.auth.views:

  • LoginView: Handles a login form and logs in a user
  • LogoutView: Logs out a user

Django provides the following views to handle password changes:

  • PasswordChangeView: Handles a form to change the user password
  • PasswordChangeDoneView: The success view the user is redirected to after a successful password change

Django also includes the following views to allow users to reset their password:

  • PasswordResetView: Allows users to reset their password. It generates a one-time use link with a token and sends it to the user's email account.
  • PasswordResetDoneView: Tells users that an email—including a link to reset their passwordhas been sent to them.
  • PasswordResetConfirmView: Allows users to set a new password.
  • PasswordResetCompleteViewThe success view the user is redirected to after successfully resetting the password.

The views listed in the preceding list can save you a lot of time when creating a website with user accounts. The views use default values that you can override, such as the location of the template to be rendered, or the form to be used by the view.

You can get more information about the built-in authentication views at https://docs.djangoproject.com/en/2.0/topics/auth/default/#all-authentication-views.

主站蜘蛛池模板: 黔南| 巴南区| 江川县| 班戈县| 崇礼县| 同江市| 合肥市| 兰考县| 望奎县| 舒兰市| 正定县| 澜沧| 丹巴县| 永昌县| 小金县| 上林县| 武宁县| 祁阳县| 琼海市| 田阳县| 泰宁县| 密云县| 吴旗县| 松桃| 岑溪市| 深水埗区| 德江县| 穆棱市| 竹北市| 彭泽县| 九龙县| 墨脱县| 孝义市| 高要市| 东港市| 濉溪县| 伊川县| 沐川县| 广丰县| 得荣县| 禄丰县|