本文整理汇总了Python中project.app方法的典型用法代码示例。如果您正苦于以下问题:Python project.app方法的具体用法?Python project.app怎么用?Python project.app使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类project
的用法示例。
在下文中一共展示了project.app方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_app
# 需要导入模块: import project [as 别名]
# 或者: from project import app [as 别名]
def create_app(config_obj=DefaultConfig, config_file=None):
app = Flask(__name__)
configure_app(app, config_obj, config_file)
configure_extensions(app)
configure_errorhandlers(app)
install_app(app)
return app
示例2: install_app
# 需要导入模块: import project [as 别名]
# 或者: from project import app [as 别名]
def install_app(app):
import flask
import project
import controllers
project.app = app
flask.current_app = app
for module in controllers.__all__:
__import__('project.controllers.%s' % module)
示例3: configure_app
# 需要导入模块: import project [as 别名]
# 或者: from project import app [as 别名]
def configure_app(app, config_obj, config_file):
if config_obj:
app.config.from_object(config_obj)
if config_file:
app.config.from_pyfile(config_file)
[os.makedirs(v) for k, v in app.config.items() if k.endswith('DIR') and not os.path.exists(v)]
示例4: configure_extensions
# 需要导入模块: import project [as 别名]
# 或者: from project import app [as 别名]
def configure_extensions(app):
from project import extensions
for extension in dir(extensions):
try:
attr = getattr(extensions, extension)
if not isinstance(attr, type) and 'init_app' in dir(attr):
attr.init_app(app)
except AttributeError as e:
print e
示例5: configure_errorhandlers
# 需要导入模块: import project [as 别名]
# 或者: from project import app [as 别名]
def configure_errorhandlers(app):
@app.errorhandler(400)
def bad_request(error):
return (jsonify(error=error.description), 400) if app.config['DEBUG'] else ("", 400)
@app.errorhandler(401)
def unauthorized(error):
return (jsonify(error=error.description), 401) if app.config['DEBUG'] else ("", 401)
@app.errorhandler(403)
def forbidden(error):
return (jsonify(error=error.description), 403) if app.config['DEBUG'] else ("", 403)
@app.errorhandler(404)
def not_found(error):
return (jsonify(error=error.description), 404) if app.config['DEBUG'] else ("", 404)
@app.errorhandler(406)
def not_acceptable(error):
return (jsonify(error=error.description), 406) if app.config['DEBUG'] else ("", 406)
@app.errorhandler(409)
def conflict(error):
return (jsonify(error=error.description), 409) if app.config['DEBUG'] else ("", 409)
@app.errorhandler(413)
def entity_too_large(error):
desc = "Request entity too large. (max is 4mg)"
return (jsonify(error=desc), 413) if app.config['DEBUG'] else ("", 413)
@app.errorhandler(415)
def unsupported_media_type(error):
return (jsonify(error=error.description), 415) if app.config['DEBUG'] else ("", 415)