我有以下路線
@app.route("/dashboard/survey/<int:survey_id>/responses", methods=["GET"])
def responses(survey_id):
responses = db.session.query(Survey, Responses).join(Responses).filter(Survey.id == survey_id).filter(
Responses.lan_code == "en").all()
return render_template('responses.html', responses=responses, kws=kws)
@app.route("/dashboard/survey/<int:survey_id>/responses/delete/<int:r_id>/<participant_folder>", methods=["POST"])
def delete_response(survey_id, r_id, participant_folder):
#response = Responses.query.get_or_404(r_id)
#db.session.delete(response)
#db.session.commit()
#pfolder = participant_folder.replace("-", "/")
#print(pfolder)
#shutil.rmtree('qdas/static/audioResponses/' pfolder, ignore_errors=True)
return redirect(url_for('responses', survey_id))
當我嘗試重定向到“回應”時,出現以下錯誤:
型別錯誤:url_for() 需要 1 個位置引數,但給出了 2 個
如果從引數中洗掉survey_id,我會收到此錯誤:
werkzeug.routing.BuildError:無法為端點“回應”構建 url。您是否忘記指定值 ['survey_id']?
有沒有辦法解決?
uj5u.com熱心網友回復:
你需要改變這一行,
return redirect(url_for('responses', survey_id))
到這個。
return redirect(url_for('responses', survey_id=survey_id))
這是因為url_for只接受一個帶有可選數量引數的端點。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/353813.html
