Example that serves static files from a directory
This commit is contained in:
19
examples/static.py
Normal file
19
examples/static.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from microdot import Microdot, send_file
|
||||
|
||||
app = Microdot()
|
||||
|
||||
|
||||
@app.route('/')
|
||||
def index(request):
|
||||
return send_file('static/index.html')
|
||||
|
||||
|
||||
@app.route('/static/<path:path>')
|
||||
def static(request, path):
|
||||
if '..' in path:
|
||||
# directory traversal is not allowed
|
||||
return 'Not found', 404
|
||||
return send_file('static/' + path)
|
||||
|
||||
|
||||
app.run(debug=True)
|
||||
10
examples/static/index.html
Normal file
10
examples/static/index.html
Normal file
@@ -0,0 +1,10 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Static File Serving Demo</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Static File Serving Demo</h1>
|
||||
<img src="static/logo.png" alt="logo">
|
||||
</body>
|
||||
</html>
|
||||
BIN
examples/static/logo.png
Normal file
BIN
examples/static/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
Reference in New Issue
Block a user