Today we learn about the flask framework
Receive information submitted by users
Take user login as an example.
First, you need to fill in the account and password to log in:
we are to open the web page to fill in the information from the beginning,
so the html should be written like this:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>测试哦</title>
</head>
<form action = "/test" method = "POST">
账号<input type="text" name="username" ><br/>
密码<input type="password" name="pw" ><br/>
<input type="submit" value="提交"><br/>
{
{msg}}
</form>
<body>
</body>
</html>
A picture to understand the
back-end is easier to write, put the code directly:
# -*- coding: utf-8 -*-
from flask import Flask,render_template,request,redirect
# 创建程序
# web应用程序
app = Flask(__name__)
@app.route('/',methods = ['POST','GET'])
def index():
return render_template("test.html")
@app.route('/test',methods = ['POST','GET'])
def login():
username = request.form.get('username')
password = request.form.get('pw')
if username =='2528104776' and password=='123':
return "登录成功!"
else:
return render_template('test.html',msg = "登录失败!")
app.run(debug = True)
There are two other things that are prone to errors: