@coolfish
2016-11-25T06:27:08.000000Z
字数 2066
阅读 1558
- 准备工作
- Flask简介
- 管理台介绍
- TODO
- 相关资料
Flask是一个微WEB框架,只包含的核心的功能,如werkzeug(python的WSGI的一个实现)、Jinja2(一个模板引擎)
#!/usr/bin/python# coding=utf-8import osfrom flask import Flask, render_templateapp = Flask(__name__)app.template_folder = os.path.dirname(os.path.basename(__file__))@app.route('/')def index():return render_template('test.html')@app.route('/login', methods=['post'])def login():return u'你已登录'if __name__ == '__main__':app.run(debug=True)
├── app│ ├── __init__.py│ ├── auth│ │ ├── __init__.py│ │ ├── forms.py│ │ ├── views.py│ ├── bug│ │ ├── __init__.py│ │ ├── views.py│ ├── models.py│ ├── static│ │ ├── css│ │ ├── img│ │ └── js│ ├── templates│ │ ├── 404.html│ │ ├── 500.html│ │ ├── apollo│ └── tools│ ├── __init__.py│ ├── apollo.py│ ├── views.py├── config.py├── manage.py└── requirements.txt
使用蓝图功能切分功能模块
#!/usr/bin/python# coding=utf-8import osimport loggingfrom flask import Flaskfrom flask.ext.sqlalchemy import SQLAlchemyfrom flask_bootstrap import Bootstrapfrom flask.ext.login import LoginManagerfrom config import configlogin_manager = LoginManager()db = SQLAlchemy()bs = Bootstrap()def create_app():app = Flask(__name__)app.config.from_object(config)db.init_app(app)bs.init_app(app)login_manager.init_app(app)login_manager.login_view = 'auth.index'# 关闭session保护强模式# login_manager.session_protection = 'strong'from .auth import auth as auth_blueprintfrom .bug import bug as bug_blueprintfrom .tools import tools as tools_blueprintapp.register_blueprint(auth_blueprint, url_prefix='/auth')app.register_blueprint(bug_blueprint)app.register_blueprint(tools_blueprint)return app
SQLAlchemy
bootstrap + jq
使用uwsgi
[uwsgi]# uwsgi 启动时所使用的地址与端口http = 0.0.0.0:8089# 指向网站目录pp= /data/testtool/lpd_test_platform/lpd_test_platform/chdir = /data/testtool/lpd_test_platform/lpd_test_platform/# python 启动程序文件wsgi-file = manage.py# python 程序内用以启动的 application 变量名callable = app# 处理器数processes = 4# 线程数threads = 2#状态检测地址stats = 127.0.0.1:9192pidfile = lpd_test_platform.pid