-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathuser_app.py
More file actions
executable file
·72 lines (47 loc) · 1.47 KB
/
user_app.py
File metadata and controls
executable file
·72 lines (47 loc) · 1.47 KB
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
65
66
67
68
69
70
71
72
#! env/bin/python
# coding: utf-8
import os
import logging
import logging.config
import click # 要import,不然app.cli.command不生效
from werkzeug.exceptions import HTTPException
from apps import createApp
from utils import RetCode, webJson, ParamsError
from configs.log_config import log_config
PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))
logging.config.dictConfig(log_config)
logger = logging.getLogger("apps")
app = createApp()
@app.errorhandler(401)
def handle401(error):
return webJson(RetCode.NEED_LOGIN)
@app.errorhandler(404)
def handle404(error):
return webJson(RetCode.PAGE_NOT_FOUND)
@app.errorhandler(ParamsError)
def handleParamsError(error):
return webJson(RetCode.PARAMS_ERROR, data=error.data)
@app.errorhandler(Exception)
def internal_server_error(e):
logger.exception("SERVER ERROR 500: %s", e)
code = 500
if isinstance(e, HTTPException):
code = e.code
return webJson(RetCode.SERVER_ERROR, data=code)
@app.cli.command(short_help='Runs a ipython shell in the app context.')
def ishell():
from IPython import embed
from apps import db
from apps.models import User, Role, Permission
embed()
@app.cli.command(short_help='Runs testcase')
def test():
import unittest
tests = unittest.TestLoader().discover('tests')
unittest.TextTestRunner(verbosity=2).run(tests)
@app.route('/')
def index():
return "hello"
if __name__ == '__main__':
app.debug = True
app.run(host="0.0.0.0")