第一步:url设置好
path('sign_up/',views.sign_up,name='sign_up'),
django2.2版本以下的这样设置
url(r'^sign_up/',views.sign_up,name='sign_up'),
第二步:新建一个名为login的html文件,并写入表单代码,这里我用的是GET方法。
这里{%url 'sign_up'%}的sign_up为上面url的name的内容
<form action="{%url 'sign_up'%}" method="GET"> <input id="SearchBox" type="text" name="zhucezhanghao" placeholder="账号"/> <input id="SearchBox" type="text" name="zhucemima" placeholder="密码"/> <input class="denglu" type="submit" value="登录"/> </form>
第三步:views.py写入接受命令,Book为我自己的模板函数,请自行创建
from django.shortcuts import render,HttpResponse from management.models import Book,Image # Create your views here. def sign_up(request):#默认首页 book_name = Book.objects.all() print("数据为",book_name) if request.method == 'GET': account = request.GET.get('zhucezhanghao') password = request.GET.get('zhucemima') print("账号:" + account + "密码:" + password) return HttpResponse(render(request, 'login.html',{"Book_name":book_name}))
接受成功