Just for fun, I am trying to understand how I can create a website with Python and Flask. That website has to run on my own computer and I will be the only client. So far I got most things I want to do working, but now I encounter a technical problem that I cannot solve.
On the client side I want to display images that are returned by the server. In my __init__.py I placed app = Flask(__name__, static_url_path='/static') and in my html document <img src="/static/images/2012035.jpg" height="150px">. This works like a charm.
But in fact, my images are in a directory d:\genealogie\documenten, which is outside the application directory and I do not want to copy more than 2000 files to the directory static/images.
I tried:
documenten = "d:\genealogie\documenten"
os.mkdir(documenten)
which gives a WinError 183 because the directory already exists.
I also tried:
documenten = "d:\genealogie\documenten"
app = Flask(__name__, static_url_path='documenten')
which gives a ValueError: urls must start with a leading slash.
I have seen quite a lot of similar questions here, but unfortunately I was unable to see how I could use the answers for my specific problem. Can I configure the website in such a way that I as a user can ask for say <img src="documenten/2012035.jpg" height="150px">, maybe with some or other localhost prefix? Any help is highly appreciated.
EDIT
What I want to do is to give the server access to directories that are outside the directory of the server. Maybe I can illustrate that by showing how easily this can be done in WAMP. There we only need to add a few lines to the file httpd.conf. For example:
Include "C:/wamp64/alias/*"
Alias /adressen "d:/adressen"
<Directory "d:/adressen">
Options Indexes FollowSymLinks Multiviews
AllowOverride all
Require all granted
</Directory>
Alias /genealogie "d:/genealogie"
<Directory "d:/genealogie">
Options Indexes FollowSymLinks Multiviews
AllowOverride all
Require all granted
</Directory>
The server and all its files are in c:/wamp64 and its subdirectories. But when we include <img src="http://localhost/genealogie/documenten/doc1064.jpg"> and <img src="http://localhost/adressen/doc5127.jpg"> in an html document, both images are nicely displayed, despite the fact that physically they reside far outside WAMP, even on different drives. So my question is: can we do this with FLASK as well?