【发布时间】:2018-06-08 16:13:14
【问题描述】:
所以我有一个 html 表单输入,基本上我想获取我输入的值并将其传递到我的 app.route(/sometext/inputvalue)
@app.route('/inputvalue')
def index():
return render_template('index.html')
【问题讨论】:
所以我有一个 html 表单输入,基本上我想获取我输入的值并将其传递到我的 app.route(/sometext/inputvalue)
@app.route('/inputvalue')
def index():
return render_template('index.html')
【问题讨论】:
您需要使用POST GET 方法捕获应用程序的表单请求。所以为此你需要一个登录方法。
像这样的。
# you don't need to redirect the template
from flask import Flask, redirect, url_for, request
@app.route('/login', methods=['POST', 'GET'])
def login():
if request.method == 'POST':
user = request.form['Email'] # suppose you have a email and password field
passe = request.form['passw']
return redirect(url_for('index', inputvalue=user)) # then you can pass email or pass
在这些事情完成并且服务器运行之后,打开你的 html 文件 并填写表格。您可以通过
查看重定向的值@app.route('/inputvalue')
def index(inputvalue):
return ('hey' + inputvalue)
【讨论】: