0

I have declared a route like so:

@views_blueprint.route('/issues/<issue_id>', methods=['PUT'])
def handle_route(issue_id):
    # do some stuff here

In my web page, I have this:

<form method="post" action="/issues/4afe21c3-5917-4699-ae72-a9fe99591e12?__METHOD_OVERRIDE__=PUT">

I found a snippet at http://flask.pocoo.org/snippets/38/, but I don't know how to make this work. In the first comment, there is a link to http://flask.pocoo.org/docs/0.10/quickstart/#hooking-in-wsgi-middlewares, but I don't see how that fits into the snippet. Specifically, they have

from werkzeug.contrib.fixers import LighttpdCGIRootFix
app.wsgi_app = LighttpdCGIRootFix(app.wsgi_app)

Would I use this?

app.wsgi_app = MethodRewriteMiddleware(app.wsgi_app)

How do I make this work together?

Mark
  • 2,058
  • 2
  • 35
  • 64
  • HTML form elements only support GET and POST requests, see [Are the PUT, DELETE, HEAD, etc methods available in most web browsers?](http://stackoverflow.com/q/165779) – Martijn Pieters Aug 21 '15 at 20:32
  • @MartijnPieters. The reason I asked is that I tried to use http://flask.pocoo.org/snippets/38/. But I still get the same issue. I know that HTML forms only support GET and POST. Do you know if the snippet actually works? Thanks for your help. – Mark Aug 21 '15 at 20:37
  • They use a special `action` attribute there, with an `METHOD_OVERRIDE` value and dedicated WSGI middleware. The snippet works, but you misunderstand what it is doing. – Martijn Pieters Aug 21 '15 at 20:39
  • And why didn't you ask a question directly about that snippet? Why did you have your form `method` set to `put` if you knew it wouldn't work? – Martijn Pieters Aug 21 '15 at 20:40
  • My advice: re-write this question to show us how you tried to apply snippet #38. We can then help you fix any problems with that. As it stands your question is either a duplicate of [Are the PUT, DELETE, HEAD, etc methods available in most web browsers?](http://stackoverflow.com/q/165779) or closable as too broad. – Martijn Pieters Aug 21 '15 at 20:49
  • @MartijnPieters Thanks for your help and advice. I edited my question, I hope it is more suitable now. – Mark Aug 21 '15 at 20:51
  • Did you actually try to use the middleware in the way you ask? Because yes, that's exactly how you'd use it. – Martijn Pieters Aug 21 '15 at 20:58

1 Answers1

0

After thinking about the question and reading Martijn's comments, I went back and looked more closely at the snippet in question. I did not initialize the wsgi_app initially, and that's why this didn't work for me. Specifically, I was missing the line

app.wsgi_app = MethodRewriteMiddleware(app.wsgi_app)

Thanks Martijn

Mark
  • 2,058
  • 2
  • 35
  • 64