Django User Authentication

Source: Internet
Author: User

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/4D/41/wKiom1ROal-z--OoAAGx3iqK8a8207.jpg "Title =" djangouser certification .jpg "alt =" wKiom1ROal-z--OoAAGx3iqK8a8207.jpg "/>

Django has a user authentication module.

Account_login is a user-defined function.

Auth. Authenticate (username = username, password = PASSWORD) is used to verify the user name and logon password. If the user name and password exist, a non-null value is returned.

(Note: Django verifies the user in the admin background user. If you want to cancel the user's logon permission, click the user name and select its property value "active" from the drop-down list .)

You can use request. user to obtain the user name.


Auth. login (request, user) is used to store the user name and password in the session. Therefore, you can access other subpages Without Having to Log On again.

From Django. contrib. Auth. decorators import login_required

From Django. contrib. Auth. decorators import logout_required

@ Login_required is used to verify whether a user logs in.

If the user does not log on, the/accounts/login/page is displayed. You can use the login_url File Settings. py to modify the value. If login_url uses the default value, you can use the URLs. py file to configure the default page.

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/4D/42/wKioL1ROcZWiFWtxAABqncGRfJU660.jpg "Title =" the user has not accessed the interface .jpg "alt =" wkiol1roczwifwtxaabqncgrfju660.jpg "/>


@ Logout_required is used to verify whether the user logs out.

Note: To use the Django user authentication module, You Need To comment out csrf in setting. py. Otherwise, a cross-site access error occurs. (Csrf error)

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/4D/42/wKioL1RObOby6fMnAAG8oSD_tWU022.jpg "Title =" Release csrf.jpg "alt =" wkiol1roboby6fmnaag8osd_twu022.jpg "/>

.

This article is from the "blue fin dolphin" blog, please be sure to keep this source http://likunheng.blog.51cto.com/9527645/1568657

2014-10-27 Django user authentication

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.