K
K
kuzdman2019-03-09 09:15:49
Python
kuzdman, 2019-03-09 09:15:49

FLASK How to insert an image from anywhere?

Good afternoon!
I need to upload an image from any directory on my computer.
For example, the following method:

.format(url_for('static', filename='filename.jpg'))

It only works if there is a static folder next to the executable file , and there is already an image there at the specified path . If you do this: Then the server gives an error 500. Is there a method for loading an image from anywhere? Thanks in advance.
.format('path/to/filename.jpg')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nicke_grodno, 2019-03-13
@Nicke_grodno

You can solve this problem in different ways, for example:
Make a symbolic link to the folder.
Or you can do it through CUSTOM_STATIC_PATH, which you specify in the config and write
return send_from_directory(app.config['CUSTOM_STATIC_PATH'], filename=filename, mimetype='image/jpeg')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question