-
Notifications
You must be signed in to change notification settings - Fork 24
/
main.py
64 lines (42 loc) · 1.52 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
from flask import Flask
from api.conf.config import SQLALCHEMY_DATABASE_URI
from api.conf.routes import generate_routes
from api.database.database import db
from api.db_initializer.db_initializer import (create_admin_user,
create_super_admin,
create_test_user)
def create_app():
# Create a flask app.
app = Flask(__name__)
# Set debug true for catching the errors.
app.config['DEBUG'] = True
# Set database url.
app.config['SQLALCHEMY_DATABASE_URI'] = SQLALCHEMY_DATABASE_URI
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
# Generate routes.
generate_routes(app)
# Database initialize with app.
db.init_app(app)
# Check if there is no database.
if not os.path.exists(SQLALCHEMY_DATABASE_URI):
# New db app if no database.
db.app = app
# Create all database tables.
db.create_all()
# Create default super admin user in database.
create_super_admin()
# Create default admin user in database.
create_admin_user()
# Create default test user in database.
create_test_user()
# Return app.
return app
if __name__ == '__main__':
# Create app.
app = create_app()
# Run app. For production use another web server.
# Set debug and use_reloader parameters as False.
app.run(port=5000, debug=True, host='localhost', use_reloader=True)