新建templ;ates/index.html 內(nèi)容如下
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="">
賬號:
<input type="text" name="name">
<br>
密碼:
<input type="password" name="password">
<br>
<input type="submit" name="submit">
</form>
</body>
</html>
在
?針對這個(gè)templates目錄需要做一下模板設(shè)置?
選擇 jinja2
新建 main_from.py
main_form.py
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/index')
def index():
return render_template("index.html")
if __name__ == '__main__':
app.run(debug=True)
效果
如果針對post提交可以修改
main_from.py代碼文章來源:http://www.zghlxwxcb.cn/news/detail-842819.html
@app.route('/index',methods=['GET',"POST"])
和修改index.html文章來源地址http://www.zghlxwxcb.cn/news/detail-842819.html
<form action="" method="post">
賬號:
<input type="text" name="name">
<br>
密碼:
<input type="password" name="password">
<br>
<input type="submit" name="submit">
</form>
到了這里,關(guān)于Python Flask 表單的使用的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!