I am trying to upload a file but the browser spinner rolls forever, server logs don’t show updates and the file doesn’t get uploaded. It sure is a newbie error but I have no clue what that is:-
static/index.html :-
html
form action="http://127.0.0.1:5000/upload" method="post" enctype="multipart/form-data"
input type="file" name="db"/
input type="submit" value="upload"/
/form
html
app.py
from flask import Flask
from flask import request
from werkzeug import secure_filename
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World!'
@app.route('/upload', methods=['GET', 'POST'])
def upload_file():
print 'upload_file'
if request.method == 'POST':
print 'post'
f = request.files['db']
f.save(secure_filename(f.filename))
if __name__ == '__main__':
app.run(debug=True)
Thanks
Env: Flask 0.9, Jinja2-2.6 and Werkzeug-0.8.3 with Python 2.7 on Win7 x64 with IE9 and Chrome
The docs say you should use
enctype="multipart/form-data".Also, I might try
method="POST"(uppercase), if only because defensive coding is a good habit, the defensive maneuver here being not assuming that Flask is bug-free.