本文整理匯總了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)