flask框架模板表单

示例

(index.html)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form method="POST">
    <textarea name="text"></textarea>
    <input type="submit" value="提交">
</form>
<!--{{text|safe}}-->
{{text}}
</body>
</html>

app.py

# _*_ coding:utf-8 _*_


from flask import Flask, render_template, request

app = Flask(__name__)


@app.route("/form", methods=["GET", "POST"])
def form():
	text = ""
	if request.method == "POST":
		text = request.form.get("text")
	return render_template("index.html", text=text)


if __name__ == '__main__':
	app.run(debug=True)

测试

1

猜你喜欢

转载自blog.csdn.net/weixin_40775077/article/details/84892500