Because the next step is to integrate with the company's UM account, it is essential to isolate the login module and implement its basic functionality.
Landing is easy, but to achieve after landing, jump to the landing page, and display the user's login status, took a little time to find the code,
Tested five or six ways to finally fix it. Even the syntax is OK.
Login.html:
{% extends "xxxx/index.html"%}{% load staticfiles%}{% block title%} User Login {% endblock%}{% block heading%}<H1>LOGIN</H2>{% endblock%}{% block content%}<Divclass= "Tm-middle"> <Divclass= "Uk-container uk-container-center"> <H3class= "Tm-article-subtitle uk-margin-top">User Login</H3> <HRclass= "Uk-grid-divider"> <Divclass= "Uk-panel uk-panel-box uk-container-center uk-width-1-3"> <H3class= "Uk-panel-title"><Iclass= "Uk-icon-user"></I>User Login</H3> <Divclass= "Uk-width-3-3"> <Div> <formAction= "{% url ' login '%}"class= "Uk-form uk-form-horizontal"role= "form"Method= "POST"> <formMethod= "POST"Action= "./?next={{redirect_to}}">{% Csrf_token%}<Divclass= "Uk-form-row"> <label for= "Id_username"class= "Uk-form-label"style= "COLOR: #e28327">User name:</label> <Divclass= "Uk-form-controls"> <inputtype= "text"name= "username"maxlength= "+"autocapitalize= "Off"AutoCorrect= "Off"class= "Form-control textinput textinput"ID= "Id_username"Required {% if Form.username.value%}value= "{{form.username.value}}"{% endif%}> </Div>{% if form.username.errors%}<Pclass= "Text-error">Incorrect user name</P>{% endif%}</Div> <Divclass= "Uk-form-row uk-width-3-3"> <label for= "Id_password"class= "Uk-form-label"style= "COLOR: #e28327">Password:</label> <Divclass= "Uk-form-controls"> <inputtype= "Password"name= "Password"maxlength= "+"autocapitalize= "Off"AutoCorrect= "Off"class= "Form-control textinput textinput"ID= "Id_password"Required>{% if form.password.errors%} <Pclass= "Text-error">incorrect user name or password</P>{% endif%}</Div> </Div> <inputtype= "hidden"name= "Next"value= "{{request.} Get.next}} ">{% if form.non_field_errors%} {% for error in form . Non_field_errors%}<Divclass= "Well well-small text-error"style= "Border:none; color:red">Please enter the correct user name and password</Div>{% endfor%} {% ENDIF%} <Buttontype= "Submit"class= "Uk-button uk-button-success uk-margin-top uk-float-right"ID= "Submit-id-submit">Login</Button> </form> </Div> </Div> </Div> </Div> </Div> <Divstyle= "height:100px"></Div>{% Endblock%}
view.py:
From Django.contrib.auth import authenticate, login, logout
@csrf_exemptdefUser_login (Request): Redirect_to= Request. Request.get ('Next',"') ifRequest.method = ='POST': Username= Request. Post.get ('username',"') Password= Request. Post.get ('Password',"') User= Authenticate (Username=username, password=password)ifUser andUser.is_active:login (Request, user)returnHttpresponseredirect (Request. Post.get ('Next','/')or '/') returnRender_to_response ("xxxx/login.html", locals (), RequestContext (Request))
urls.py:
URL (r'^accounts/login/$', User_login, name='login'),
Django Custom user login and login to jump to the pre-landing page implementation