3

I wrote this easy program:

@app.route('/puttest/', methods=['GET', 'PUT'])
def upload_file():
    if request.method == 'PUT':
        return 'Hello, {}!'.format(request.form['name'])
    else:
        return '''
            <title>Does it work ?</title>
            <h1>PUT test</h1>
            <form action=http://localhost:8887/puttest/ method=put>
                <input type=text name=name>
                <input type=submit value=try>
            </form>

        '''

if __name__ == '__main__':
    app.run('0.0.0.0', 8887)

It works perfectly for GET method, but it doesn't work with PUT. Trying to send put message, I can see this error at a browser:

Method Not Allowed

The method is not allowed for the requested URL.

What has happened to put method ?

It will work fine if I change put method on post everywhere in program.

faoxis
  • 1,912
  • 5
  • 16
  • 31

1 Answers1

7

PUT won't work with HTML method attribute. Allowed values are: method = get|post

You have to use POST in Webforms:

@app.route('/puttest/', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
    return 'Hello, {}!'.format(request.form['name'])
else:
    return '''
        <title>Does it work ?</title>
        <h1>PUT test</h1>
        <form action=http://localhost:8887/puttest/ method=post>
            <input type=text name=name>
            <input type=submit value=try>
        </form>
    '''

Further informations at: Using PUT method in HTML form and HTML Standard

Community
  • 1
  • 1
Nils
  • 2,665
  • 15
  • 30