I'm attempting to add a file addition button that uploads a file to a folder on my Flask Heroku app but I get an application error when I hit the submit button.
class PhotoForm(Form):
photo = FileField('Your photo')
submit = SubmitField('Submit')
@app.route('/upload', methods=('GET', 'POST'))
def upload():
form = PhotoForm()
if form.validate_on_submit():
filename = secure_filename(form.photo.data.filename)
form.photo.data.save("uploads/" + filename)
else:
filename = None
return render_template('upload.html', form=form, filename=filename)
Here is the upload.html:
{% extends "base.html" %}
{% import "bootstrap/wtf.html" as wtf %}
{% block page_content %}
<form action="uploads/" method="POST" enctype="multipart/form-data">
{{ wtf.quick_form(form)}}
</form>
{{filename}}
{% endblock %}
Here is the error it throws:
2015-01-21T20:52:24.834249+00:00 heroku[router]: sock=backend at=error code=H18
desc="Request Interrupted" method=POST path="/uploads/" host=xxxx.h
erokuapp.com request_id=18dabdc3-400e-4c8b-ba8a-8d52d4cc1cb5 fwd="8.34.183.2" dy
no=web.1 connect=3ms service=6ms status=503 bytes=568
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…