-
Notifications
You must be signed in to change notification settings - Fork 1
/
public_app.py
54 lines (41 loc) · 1.41 KB
/
public_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
53
54
#!/usr/bin/env python
import argparse
import datetime
import logging
from flask import Flask, render_template
import app_config
from render_utils import make_context
app = Flask(__name__)
app.config['PROPAGATE_EXCEPTIONS'] = True
file_handler = logging.FileHandler(app_config.APP_LOG_PATH)
file_handler.setLevel(logging.INFO)
app.logger.addHandler(file_handler)
app.logger.setLevel(logging.INFO)
# Example application views
@app.route('/%s/test/' % app_config.PROJECT_SLUG, methods=['GET'])
def _test_app():
"""
Test route for verifying the application is running.
"""
app.logger.info('Test URL requested.')
return datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
# Example of rendering HTML with the rig
import static
from render_utils import urlencode_filter
app.register_blueprint(static.static, url_prefix='/%s' % app_config.PROJECT_SLUG)
app.jinja_env.filters['urlencode'] = urlencode_filter
@app.route ('/%s/' % app_config.PROJECT_SLUG, methods=['GET'])
def index():
"""
Example view rendering a simple page.
"""
return render_template('index.html', **make_context(asset_depth=1))
# Boilerplate
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-p', '--port')
args = parser.parse_args()
server_port = 8000
if args.port:
server_port = int(args.port)
app.run(host='0.0.0.0', port=server_port, debug=app_config.DEBUG)