-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathapp.py
52 lines (38 loc) · 1.32 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# encoding:utf-8
import os
import sys
from flask import Flask, redirect, url_for, send_from_directory
from gallery.views import gallery
import settings
from logging.config import dictConfig
dictConfig({
'version': 1,
'formatters': {'default': {
'format': '[%(asctime)s] %(levelname)s in %(module)s: %(message)s',
}},
'handlers': {'wsgi': {
'class': 'logging.StreamHandler',
'stream': 'ext://flask.logging.wsgi_errors_stream',
'formatter': 'default'
}},
'root': {
'level': 'INFO',
'handlers': ['wsgi']
}
})
ROOT_DIR = os.path.dirname(__file__)
UPLOAD_DIR = os.path.join(ROOT_DIR, 'uploads')
app = Flask(__name__)
app.register_blueprint(gallery, url_prefix='/gallery')
app.config['GALLERY_ROOT_DIR'] = settings.GALLERY_ROOT_DIR if len(sys.argv) < 2 else sys.argv[1]
app.config['UPLOAD_ALLOWED_EXTENSIONS'] = settings.UPLOAD_ALLOWED_EXTENSIONS
@app.route('/')
def index():
return redirect(url_for('gallery.show_gallery'))
@app.route('/cdn/<path:filename>')
def custom_static(filename):
return send_from_directory(app.config['GALLERY_ROOT_DIR'], filename)
if __name__ == '__main__':
app.logger.info('Listening on http://localhost:8000')
app.logger.info(f'allowed extensions: {settings.UPLOAD_ALLOWED_EXTENSIONS}')
app.run(port=8000, debug=True)