在Heroku上部署的Flask应用无法执行一致的GET请求

时间:2019-03-06 05:24:02

标签: post heroku flask web-applications get

提交表格后,我的Heroku Flask应用程序返回不同的结果。我检查了 heroku日志,并意识到该应用程序不一致地执行其GET请求(在表单的POST请求之后)。

有时GET请求在POST请求之后执行,我得到了想要的结果。其他时候,GET请求没有执行,我哭了

示例:

A。成功执行

2019-03-06T04:56:41.479817+00:00 app[web.1]: 10.7.252.94 - - [06/Mar/2019:04:56:41 +0000] "POST /hahaha HTTP/1.1" 302 229 "https://sg-property-99co.herokuapp.com/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36"
2019-03-06T04:56:41.480641+00:00 heroku[router]: at=info method=POST path="/hahaha" host=sg-property-99co.herokuapp.com request_id=3cf26d28-3c4d-4fba-a6f8-b5178dc3c154 fwd="14.187.133.78" dyno=web.1 connect=1ms service=3ms status=302 bytes=454 protocol=https
2019-03-06T04:56:41.798715+00:00 heroku[router]: at=info method=GET path="/dashboard/" host=sg-property-99co.herokuapp.com request_id=59d2838b-1503-44bb-9150-5505fbea9100 fwd="14.187.133.78" dyno=web.1 connect=1ms service=3ms status=200 bytes=689 protocol=https
2019-03-06T04:56:41.798106+00:00 app[web.1]: 10.7.252.94 - - [06/Mar/2019:04:56:41 +0000] "GET /dashboard/ HTTP/1.1" 200 481 "https://sg-property-99co.herokuapp.com/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36"
2019-03-06T04:56:42.595669+00:00 heroku[router]: at=info method=GET path="/dashboard/_dash-dependencies" host=sg-property-99co.herokuapp.com request_id=ed26a97f-0d0b-40a4-94dd-1a3cba1ee7ee fwd="14.187.133.78" dyno=web.1 connect=1ms service=2ms status=200 bytes=154 protocol=https
2019-03-06T04:56:42.589600+00:00 heroku[router]: at=info method=GET path="/dashboard/_dash-layout" host=sg-property-99co.herokuapp.com request_id=267b5e36-b333-4b19-b4d6-8c33e8ef9ceb fwd="14.187.133.78" dyno=web.1 connect=1ms service=2ms status=200 bytes=329 protocol=https
2019-03-06T04:56:42.588952+00:00 app[web.1]: 10.7.252.94 - - [06/Mar/2019:04:56:42 +0000] "GET /dashboard/_dash-layout HTTP/1.1" 200 176 "https://sg-property-99co.herokuapp.com/dashboard/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36"
2019-03-06T04:56:42.594966+00:00 app[web.1]: 10.30.127.194 - - [06/Mar/2019:04:56:42 +0000] "GET /dashboard/_dash-dependencies HTTP/1.1" 200 3 "https://sg-property-99co.herokuapp.com/dashboard/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36"

B。执行失败

2019-03-06T04:59:05.457714+00:00 heroku[router]: at=info method=POST path="/hahaha" host=sg-property-99co.herokuapp.com request_id=73fd66f6-4abb-4f39-bd1a-20b1dc5dab36 fwd="14.187.133.78" dyno=web.1 connect=1ms service=2ms status=200 bytes=634 protocol=https
2019-03-06T04:59:05.457355+00:00 app[web.1]: 10.47.180.215 - - [06/Mar/2019:04:59:05 +0000] "POST /hahaha HTTP/1.1" 200 473 "https://sg-property-99co.herokuapp.com/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36"

其他人在部署的应用程序中是否遇到相同的问题?有什么可能的原因以及如何规避?

其他信息

我的服务器端Python程序

@application.route('/hahaha', methods=['POST','GET'])
def show_barcharts():	
    global plot_charts_cue
    global app_dash
    global graph2		
    global graph3		
    global graph4		
    if (request.method == 'POST') and plot_charts_cue:
	    app_dash.layout = html.Div(style=dict(textAlign="center", display="inline-block"), children=[graph2, graph3, graph4])
	    return flask.redirect('/dashboard/')
    else: return render_template('chart_error.html')

我的HTML表单

<form method=post action="/hahaha" redirect="/hahaha" data-redirect="/hahaha">
	<input type="hidden" name="form_name" value="form4">
	<center><h3 class="heading-3">Click {{form4.submit_chart(class_="button")}} to see interactive barcharts</h3></center></form>

0 个答案:

没有答案