0

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?

NeoVe
  • 3,857
  • 8
  • 54
  • 134
  • Possible duplicate of [How to pass uploaded image to template.html in Flask](https://stackoverflow.com/questions/11262518/how-to-pass-uploaded-image-to-template-html-in-flask) – metatoaster Feb 12 '18 at 02:34
  • 1
    You'll want to actually render an `` tag if you want to show any images – OneCricketeer Feb 12 '18 at 05:17

0 Answers0