I have this code on my app.py
:
from werkzeug import secure_filename
from flask import Flask, render_template, request
from flask.ext.uploads import UploadSet, configure_uploads, IMAGES
app = Flask(__name__, template_folder='../templates')
photos = UploadSet('photos', IMAGES)
app.config['UPLOADED_PHOTOS_DEST'] = 'static/img'
configure_uploads(app, photos)
@app.route('/')
def hello():
return "Hello World!"
@app.route('/upload', methods=['GET', 'POST'])
def upload():
if request.method == 'POST' and 'photo' in request.files:
filename = photos.save(request.files['photo'])
return 'static/img/'+str(secure_filename(filename))#filename =
return render_template('upload.html')
if __name__ == '__main__':
app.run(debug=True)
On my upload.html
:
<html>
<head>
<title>Upload</title>
</head>
<body>
<form method=POST enctype=multipart/form-data action="{{ url_for('upload') }}">
<input type=file name=photo>
<input type="submit">
</form>
</body>
</html>
Right now, it only shows the filename of the last uploaded image, so, how can I actually show the image and not the image name?
For more details, this is my routes.py
:
from app import app
@app.route('/upload')
def upload():
return upload
EDIT
I have used the other answer, but it doesn't meet my needs, since I'm still facing Error 404, so I think it has something to do with my POST
and GET
requests.
Maybe should I seprate them both on different functions?