后端的代码
from flask import Flask,render_template,request
app = Flask(__name__)
@app.route('/')
def index():
return render_template('06_index.html')
@app.route('/register',methods=['POST'])
def register():
print(request.path)
print(request.values)
print(request.data)
print(request.method)
print(request.headers)
print(request.host)
print(request.full_path)
print(request.url)
print(request.form)
print(request.args)
name = request.form.get('name')
pwd = request.form.get('pwd')
hobby = request.form.getlist('hobby')
return '注册成功'
@app.route('/register1',methods=['GET'])
def register1():
print(request.path)
print(request.values)
print(request.data)
print(request.method)
print(request.headers)
print(request.host)
print(request.full_path)
print(request.url)
print(request.form)
print(request.args)
name = request.args.get('name')
pwd = request.args.get('pwd')
hobby = request.values.getlist('hobby')
return '注册成功'+ name
if __name__ == '__main__':
app.run(debug=True)
前端的代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="/register1" method="get">
<div>账号:<input type="text" name="name"></div>
<div>密码:<input type="password" name="pwd"></div>
<div>
爱好:吃<input type="checkbox" name="hobby" value="吃">
喝:<input type="checkbox" name="hobby" value="喝">
玩:<input type="checkbox" name="hobby" value="玩">
</div>
<div><input type="submit" value="提交"></div>
</form>
<form action="/register" method="post">
{
<div>账号:<input type="text" name="name"></div>
<div>密码:<input type="password" name="pwd"></div>
<div> 爱好:吃<input type="checkbox" name="hobby" value="吃">
喝:<input type="checkbox" name="hobby" value="喝">
玩:<input type="checkbox" name="hobby" value="玩"> </div>
<div><input type="submit" value="提交"></div>
</form>
</body>
</html>