1. 程式人生 > >flask框架模板表單

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