Reputation: 61
I have the following routes
@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))
When I try to redirect to 'responses' I get the following error:
TypeError: url_for() takes 1 positional argument but 2 were given
And if remove survey_id from the arguments I get this error:
werkzeug.routing.BuildError: Could not build url for endpoint 'responses'. Did you forget to specify values ['survey_id']?
Is there any way around this?
Upvotes: 0
Views: 740
Reputation: 1155
You need to change this line,
return redirect(url_for('responses', survey_id))
to this one.
return redirect(url_for('responses', survey_id=survey_id))
This is because url_for
accepts only one endpoint with an optional number of arguments.
Upvotes: 4