[英]How to mock test Flask endpoints that mainly interact with 3rd party APIs?
[英]How to have a 3rd party application interact with flask
我有一個第 3 方 C# 應用程序,我想與我制作的 flask webapp 進行交互。 基本上,每次 C# 應用程序向 flask 發送 POST 請求時,flask 都會收到請求,進行一些更改,然后刷新頁面以更新更改。
但是,現在發生的事情是:Flask 獲取請求,進行更改,將 HTML 代碼返回到我的應用程序,而不是刷新頁面。 數據已更改,刷新頁面后我可以看到它。 但我希望 flask 在數據更改時刷新頁面。
這是我的 flask 代碼:
@app.route('/stats/', methods=["POST", "GET"])
def display():
global g_hours
if request.method == "POST":
g_hours = request.form["hours"]
return redirect("/stats/")
return render_template("statsOverview.html", hours=g_hours)
這是我的 C# 代碼:
var content = new FormUrlEncodedContent(values);
var response = await client.PostAsync("http://127.0.0.1:5000/stats/", content);
var responseString = await response.Content.ReadAsStringAsync();
現在,redirect() 將 HTML 代碼返回到我的應用程序,而不是重定向到頁面(刷新頁面)。
嘗試return redirect(url_for('display'))
@app.route('/stats/', methods=["POST", "GET"])
def display():
global g_hours
if request.method == "POST":
g_hours = request.form["hours"]
return redirect(url_for('display'))
return render_template("statsOverview.html", hours=g_hours)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.