1、创建HTML
在HelloWorld根目录下创建templates文件夹

并在文件夹中创建login.html文件,编辑html文件

2、编辑Login函数
在api_test/views.py文件里,编辑Login函数
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.shortcuts import render
from django.http.response import HttpResponse
from django.shortcuts import render_to_response
# Create your views here.
def Login(request):
if request.method == 'POST':
username = request.POST.get('username')
return HttpResponse(username)
else:
return render_to_response('login.html')
3、添加html路径并关闭认证


4、重启服务并使用浏览器访问
#python manage.py runserver 8001
使用浏览器访问,输入用户名和密码,并点击登录按钮

登录后,显示为:

网友评论