简体   繁体   中英

Return from post-request with parameters in URL

@app.route('/path', methods= ['POST', 'GET'])
def path():
    results = getResults(request)
    return render_template('path_result.html', results=results)

I need a way to update the URL. Currently, when the user submits their form, the results are returned and rendered, but the URL does not contain the submitted page parameters. So the url remains as /path, instead of /path?formDataA=foo

Mainly I need this to allow users to share the links to specific results with one another easily.

When you POST your data to a route you can't see the parameter. Thats the normal way. You can send your form as GET then all form parameters are appended to your url but i would prefer the POST way.

After posting the values you can redirect to another route where you display your values. When redirecting you can append some parameters your url that you need.

So make a method that process your form data. After processing redirect to another page where you display that values.

https://laravel.com/docs/8.x/routing#redirect-routes

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM