Interface Interface testing framework -Django development post

Description: simple login interfaces

 

A directory structure is as follows

 

 Two implementation steps

1 Create a folder templates, add login.html file (page) in the folder

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>login</title>
</head>
<body>
<form action="/login/" method="POST">
<h1>用户名:<input name="username"></h1>
<h1>密码:<input name="password"></h1>
<input type="submit" value="登录">
</form>
</body>
</html>

运行效果如下:

 

 

2 in the polls folder (app), add views.py file defines the login function that returns the username login page

 

 

3 in the polls folder, add files urls.py

 

 

Add 4 login path under urls.py project import module include

 

 5在settings中添加login.html的路径,不然会报错

 

 

6 注释掉此项,去掉验证信息,登录时候不会报错

 

 

7运行manage.py,启动服务

 

 

 

8 页面中输入地址http://127.0.0.1:8000/login/

 

 

9 输入用户名,密码,点击登录

 

 根据调用login函数。返回值为username的值

 

 

10 可通过F12查看页面请求post

请求地址。方式,入参,返回结果 

 

 

 

 

Guess you like

Origin www.cnblogs.com/lucky-sunshine/p/12144531.html