16.用户登录

先改urls.py,之前的TemplateView.as_view是django自带的功能,改成了自己做的响应函数用于处理业务逻辑:

from django.conf.urls import url
from django.contrib import admin
from django.views.generic import TemplateView
import xadmin

from users.views import login

urlpatterns = [
    url(r'^xadmin/', xadmin.site.urls),
    url('^$', TemplateView.as_view(template_name="index.html"),name="index"),
    url('^login/$', login,name="login")
]

然后 users的views.py:

from django.shortcuts import render

# Create your views here.
def login(request):
    if request.method == "POST":
        pass
    elif request.method == "GET":
        return render(request, "login.html", {})

login.html的POST表单结束前,在这行之上写上{% csrf_token %}。

你可能感兴趣的:(16.用户登录)