Issue A Post Request With Url_for In Flask
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
Solution 1:
All links are GET
requests. You can't force a POST
.
An alternative would be this:
@app.route('/save_info/<filepath>', methods=['GET', 'POST'])defsave_info(filepath):
if request.method == 'POST'or filepath:
...
You'll have to find a nice way to force your code to ignore that you sent a GET
request.
Solution 2:
You could either make a form that contains only a submit button, or send the POST using AJAX or some other client side scripting. As far as I know, you can't make a link send a POST, though.
Solution 3:
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><ahref = "{{ url_for('save_info', __METHOD_OVERRIDE__='POST', filepath=s.name ) }}"><divclass="nodes">{{ s.title}} - {{ song.owner }}</div></a></li>
Post a Comment for "Issue A Post Request With Url_for In Flask"