-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
56 lines (44 loc) · 1.54 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
53
54
55
try:
from flask import Flask
except ModuleNotFoundError as e:
print(e)
print('Make sure to run: pip install -r module-reqs.txt')
from flask import Flask, render_template
import blueprints
import config
import sys
import os
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-d', '--development',
action='store_true', # act like a flag
help='a flag for indicating the app will run for local development')
args = parser.parse_args()
STATIC_PATH = config.STATIC_PATH
# Initialize Flask app
app = Flask(__name__, template_folder='templates', static_folder=STATIC_PATH)
# Register the controllers
app.register_blueprint(blueprints.main.home)
app.register_blueprint(blueprints.main.info)
app.register_blueprint(blueprints.main.support)
app.register_blueprint(blueprints.learn.learn, subdomain='learn')
app.register_blueprint(blueprints.teach.teach, subdomain='teach')
# Subdomain setup
serverName = 'sevenmilecoding.org'
if args.development:
serverName = '7mc:' + str(config.env['port']) # so subdomains work on local machine
app.config['SERVER_NAME'] = serverName
# add global variables to jinja templates
@app.context_processor
def inject_globals():
return dict(**config.GLOBAL_JINJA)
@app.errorhandler(404)
def page_not_found(e):
return render_template('main/404.html')
# Listen on external IPs
if __name__ == '__main__':
# listen on external IPs
if args.development: # only arguments will be pased to development
app.run(host=config.env['host'], port=config.env['port'], debug=True)
else:
app.run()