-
Notifications
You must be signed in to change notification settings - Fork 7
/
app.py
33 lines (26 loc) · 1.06 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
from flask import Flask, render_template
from config import DevelopmentConfig, ProductionConfig
from blueprints.api import API
from blueprints.public import public
"""
Register API from modules/api.py
From http://flask.pocoo.org/docs/1.0/views/#method-views-for-apis
"""
def register_api(app, view, endpoint, url, pk='id', pk_type='string'):
view_func = view.as_view(endpoint)
app.add_url_rule(url, defaults={pk: None},
view_func=view_func, methods=['GET',])
app.add_url_rule(url, view_func=view_func, methods=['POST',])
app.add_url_rule('%s<%s:%s>' % (url, pk_type, pk), view_func=view_func, methods=['POST', 'GET', 'PUT', 'DELETE'])
def create_app(config):
app = Flask(__name__)
app.config.from_object(config)
app.register_blueprint(public)
register_api(app, API, 'api', '/api/events', pk='id', pk_type='int')
@app.errorhandler(404)
def handle_four_oh_four(err):
return render_template("404.html"), 404
return app
app = create_app(DevelopmentConfig)
if __name__ == '__main__':
app.run(host="0.0.0.0")