-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
46 lines (32 loc) · 1.1 KB
/
main.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
# -*- coding:utf-8 -*-
import os
import sys
from empty import Empty
from flask import render_template
# apps is a special folder where you can place your blueprints
PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))
sys.path.insert(0, os.path.join(PROJECT_PATH, "apps"))
basestring = getattr(__builtins__, 'basestring', str)
class App(Empty):
def configure_views(self):
@self.route('/')
def index_view():
return render_template("index.html")
def config_str_to_obj(cfg):
if isinstance(cfg, basestring):
module = __import__('config', fromlist=[cfg])
return getattr(module, cfg)
return cfg
def app_factory(config, app_name, blueprints=None):
# you can use Empty directly if you wish
app = App(app_name)
config = config_str_to_obj(config)
app.configure(config)
app.rate_limit(["5 per minute"])
app.add_blueprint_list(blueprints or config.BLUEPRINTS)
app.setup()
return app
def heroku():
from config import Config, project_name
# setup app through APP_CONFIG envvar
return app_factory(Config, project_name)