Flask:用户输入[POST]

时间:2015-04-06 14:02:29

标签: python html forms flask

当用户提交输入时,我尝试执行将用户输入作为参数的脚本,并将用户重定向回主页。当我运行下面的脚本时,除了重定向之外,一切似乎都有效。当我在网络浏览器中点击提交时,我收到了无数据提交。

from flask import Flask, render_template, redirect, request
from Index_generator import index_generator
from Yelp_api import request_yelp

@app.route('/home_city',methods = ['POST'])
def home_city():
    CITY=request.form['city']
    request_yelp(DEFAULT_LOCATION=CITY) #This function executes the script
    return redirect('/')

1 个答案:

答案 0 :(得分:0)

如果将url_forredirect一起使用,该怎么办?

from flask import Flask, render_template, redirect, request, url_for
from Index_generator import index_generator
from Yelp_api import request_yelp

@app.route('/', methods = ['GET'])
def home():
    return 'Hello World'

@app.route('/home_city',methods = ['POST'])
def home_city():
    CITY=request.form['city']
    request_yelp(DEFAULT_LOCATION=CITY) #This function executes the script
    return redirect(url_for('home'))