templates 文件夹是放置html文件的,否则路径不对会报错。
demo1.py 文件内容
from flask import Flask
from flask import render_template
from flask import request
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World! lbw'
@app.route('/index_1', methods=['GET', 'POST'])
def index_():
if request.method == 'GET':
return render_template('index.html')
if request.method == 'POST':
name = request.form.get('name')
password = request.form.get('password')
print("name :", name)
print("password :", password)
return "提交成功"
if __name__ == '__main__':
app.run(host="127.0.0.1", port=8888)
HTML网页文件内容
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="" method="post">
账号:
<input type="text" name="name">
<br>
密码:
<input type="password" name="password">
<input type="submit" name="submit">
</form>
</body>
</html>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)