I have some javascript that queries the server and returns a value that will be used as the parameter for the redirect url:
<script>
$.post("/api/server", post_data, function(result) {
var parameter = result['parameter'];
// Do page redirect, but how do I pass my paramter to url_for()???
window.location = "{{ url_for('doit', param=???) }}";
});
</script>
The flask route:
@app.route("/doit/<param>")
def doit(param):
print param
return render_template("done.html")
Basically, when the $.post
completes, it returns a value that I need as the parameter for the page redirect. How can I dynamically create this page redirect URL?
window.location.href = "{{ url_for('doit', param="+parameter+") }}";
I was being dumb. I can store results in my user's session and then access it later in the new request.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.