I'm trying to issue a POST request within a Jinja template in Flask. However, parameters are passed in via GET by default, and this particular method only accepts POST requests.
I tried specifying _method
, as below, but it still passes the parameter with GET instead of POST.
<li><a href = "{{ url_for('save_info', _method='POST', filepath=s.name ) }}"><div class="nodes">{{ s.title}} - {{ song.owner }}</div></a></li>
(The error message is the same whether or not I specify _method
).
Flask url_for is defined as a function that enables developers to build and generate URLs on a Flask application. As a best practice, it is the url_for function that is required to be used, as hard coding the URL in templates and view function of the Flask application tends to utilize more time during modification.
The url_for() function is very useful for dynamically building a URL for a specific function. The function accepts the name of a function as first argument, and one or more keyword arguments, each corresponding to the variable part of URL.
A GET message is send, and the server returns data. POST. Used to send HTML form data to the server. The data received by the POST method is not cached by the server.
You can add a Middelway which search for a GET argument which overwrite the http method. Look there: http://flask.pocoo.org/snippets/38/
Your new link will look like this:
<li><a href = "{{ url_for('save_info', __METHOD_OVERRIDE__='POST', filepath=s.name ) }}"><div class="nodes">{{ s.title}} - {{ song.owner }}</div></a></li>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With