-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
58 lines (45 loc) · 1.69 KB
/
__init__.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
56
57
58
from flask import Flask, render_template
from flask_migrate import Migrate
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import MetaData
#from flaskext.markdown import Markdown
# SQLite error solution : MetaData, naming_convention
naming_convention = {
"ix": "ix_%(column_0_labels)s",
"uq": "uq_%(table_name)s_%(column_0_name)s",
"ck": "ck_%(table_name)s_%(column_0_name)s",
"fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
"pk": "pk_%(table_name)s"
}
# db = SQLAlchemy()
db = SQLAlchemy(metadata=MetaData(naming_convention=naming_convention))
migrate = Migrate()
# error page
def page_not_found(e) :
return render_template('404.html'), 404
def create_app() :
app = Flask(__name__)
# app.config.from_object(config)
app.config.from_envvar('APP_CONFIG_FILE')
# ORM
## SQLite error solution : migrate.init_app(app, db, render_as_batch=True)
db.init_app(app)
if app.config['SQLALCHEMY_DATABASE_URI'].startswith("sqlite") :
migrate.init_app(app, db, render_as_batch=True)
else :
migrate.init_app(app, db)
from jump2 import models # create table
# blueprint : endpoint
from jump2.views import main_view, question_view, answer_view, auth_view
app.register_blueprint(main_view.bp)
app.register_blueprint(question_view.bp)
app.register_blueprint(answer_view.bp)
app.register_blueprint(auth_view.bp)
# filter
from jump2.filter import filter_datetime
app.jinja_env.filters['datetime'] = filter_datetime
# markdown
#Markdown(app, extensions=['nl2br', 'fenced_code'])
# error page
app.register_error_handler(404, page_not_found)
return app