Serve images from a separate direcory configured in an external config
file (config.py)
This commit is contained in:
parent
d45d1347bd
commit
f0fb5f0d9f
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
__pycache__/
|
1
config.py
Normal file
1
config.py
Normal file
@ -0,0 +1 @@
|
||||
imgdir = "/home/mandlm/Foto Export/2018/09/2018-09-03"
|
@ -1,8 +1,10 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
from flask import Flask, render_template
|
||||
from flask import Flask, render_template, send_from_directory
|
||||
from random import randint
|
||||
|
||||
import config
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
||||
@ -11,5 +13,10 @@ def hello():
|
||||
return render_template("hello.html", num=randint(1, 23))
|
||||
|
||||
|
||||
@app.route("/img/<path:filename>")
|
||||
def image(filename):
|
||||
return send_from_directory(config.imgdir, filename)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run()
|
||||
|
@ -2,5 +2,6 @@
|
||||
<body>
|
||||
<p>Hello slider number {{ num }}!</p>
|
||||
<p><img src="{{ url_for("static", filename="cat.jpg") }}"></p>
|
||||
<p><a href="{{ url_for("image", filename="IMG_0001.jpg") }}">Image</a></p>
|
||||
</body>
|
||||
</html>
|
||||
|
Reference in New Issue
Block a user