1

I get into trouble when I would like to store the image_url for updating the picture of my product. The flask extensions that I used are flask-reuploaded and flask-wtf. I have tried to search a lot but still cannot figure out a solution. Could you help me, please? This is my app.py:

@app.route('/admin/add', methods=['GET', 'POST'])
def add():
    form = AddProduct()
    
    if form.validate_on_submit():
        image_name = photos.save(form.image.data)
        image_url = photos.url(image_name)
        return '<h1>{}</h1>'.format(image_url)
    return render_template('admin/add-product.html', admin=True, form=form)

I also include <form method="POST" action="{{ url_for('add') }}" enctype="multipart/form-data"> in my template but it doesn't help. The error message is that werkzeug.routing.BuildError: Could not build url for endpoint '_uploads.uploaded_file' with values ['filename', 'setname']. Did you mean 'product' instead? Thank you in advance, everyone.

1 Answers1

0

I had the same issue and managed to fix it this way. I am sure someone who is way better at Python can give an explanation to what I did to fix it.

The problem is this blueprint route is not registered: _uploads.uploaded_file. I set this config item UPLOADS_AUTOSERVE=True This allows the default route in flask_uploads.py to be used. I didn't bother with this, but it also looks like you could set the base_url in the UploadConfiguration. The class says

:param base_url: The URL (ending with a /) that files can be downloaded from. If this is None, Flask-Reuploaded will serve the files itself.

Also, I would add, you don't need to save the url. You can do upload_set.url(filename). Or upload_set.path(filename) if you wanted to modify it with a different module like PIL.