2015-04-06 97 views
0

當用戶提交輸入時,我試圖執行一個腳本,將用戶輸入作爲參數並將用戶重定向回主頁。當我運行下面的腳本時,一切似乎都適用於重定向的例外。當我點擊網頁瀏覽器提交時,我收到沒有數據提交。燒瓶:用戶輸入[POST]

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('/') 

回答

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')) 
+0

感謝您的回覆,Mauro。出於某種原因,我仍然收到「沒有收到數據」,「無法加載網頁,因爲服務器沒有發送數據」,以及「錯誤代碼:ERR_EMPTY_RESPONSE」。嗯 – Ash

+0

把一些調試像['pdb'](https://docs.python.org/2/library/pdb.html)或['ipdb'](https://github.com/gotcha/ipdb)可以幫你。 –