![](/img/trans.png)
[英]Restrict Access for FLASK Application deployed to AWS ElasticBeanStalk
[英]Access request parameters from flask application deployed in openshift
我有一個python網絡應用,可以對通過POST / GET參數發送給它的數據進行計算。 該應用程序可以在我的機器上完美運行,但是當部署到openshift時,它無法訪問參數,錯誤為32:管道損壞
然后,我使用此快速入門回購僅關注服務器代碼而不關注應用程序代碼。
可以區分POST和GET請求,並在此結束
這是相關的python代碼:
@app.route('/', methods=['GET','POST'])
def index():
result = ""
if request.method == "GET":
name = request.form['name'] if "name" in request.form else ""
result = "We received a GET request and the value for <name> is :%s" % name
elif request.method == "POST":
result = "We received a POST request"
else :
result = "We don't know what type of request we have received"
return result
所以我只想知道如何訪問參數。
不要在生產中使用Flask的開發服務器。 使用可以處理並發請求的適當WSGI服務器,例如Gunicorn 。 現在,請嘗試打開服務器的線程模式,然后查看它是否有效。
app.run(host="x.x.x.x", port=1234, threaded=True)
您可以通過以下方式從POST請求中獲取表單數據:
name = request.form.get("name")
重構:
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
name = request.form.get("name")
result = "We received a POST request and the value for <name> is - {0}".format(name)
else:
result = "This is a GET request"
return result
請參閱Flask官方文檔以了解有關Request對象的更多信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.