python config_Python config.app_config方法代码示例

本文整理汇总了Python中config.app_config方法的典型用法代码示例。如果您正苦于以下问题:Python config.app_config方法的具体用法?Python config.app_config怎么用?Python config.app_config使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块config的用法示例。

在下文中一共展示了config.app_config方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: create_app

​点赞 3

# 需要导入模块: import config [as 别名]

# 或者: from config import app_config [as 别名]

def create_app(config_name):

app = Flask(__name__, instance_relative_config=True)

app.config.from_object(app_config[config_name])

app.config.from_pyfile('config.py')

Bootstrap(app)

db.init_app(app)

login_manager.init_app(app)

login_manager.login_message = "You must be logged in to access this page."

login_manager.login_view = "auth.login"

migrate = Migrate(app, db)

from app import models

from .admin import admin as admin_blueprint

app.register_blueprint(admin_blueprint, url_prefix='/admin')

from .auth import auth as auth_blueprint

app.register_blueprint(auth_blueprint)

from .home import home as home_blueprint

app.register_blueprint(home_blueprint)

return app

开发者ID:mbithenzomo,项目名称:project-dream-team-one,代码行数:26,

示例2: create_app

​点赞 2

# 需要导入模块: import config [as 别名]

# 或者: from config import app_config [as 别名]

def create_app(config_name):

if config_name not in app_config:

raise ConfigError("{} is a wrong config name.".format(config_name))

app = Flask(__name__)

app.config.from_object(app_config[config_name])

from app.user import user_blueprint

from app.information import info_blueprint

from app.view import view_blueprint

app.register_blueprint(user_blueprint)

app.register_blueprint(info_blueprint)

app.register_blueprint(view_blueprint)

from app.extensions import display_plan_type, display_play, display_user, tracer_config

jinja_env = app.jinja_env

jinja_env.filters['plan_type'] = display_plan_type

jinja_env.filters['plan_name'] = display_play

jinja_env.filters['user_type'] = display_user

db.init_app(app)

tool_bar.init_app(app)

login_manager.init_app(app)

admin.init_app(app)

if app.config.get("TRACER"):

tracer_config.initialize_tracer()

@app.before_request

def init_tracer():

import opentracing

from app.extensions import tracer_config

span = opentracing.tracer.start_span(str(request.url))

span.set_tag('user_agent', request.user_agent)

span.log_event("request args", payload=dict(args=request.args, form=request.form))

g.tracer_span = span

@app.after_request

def close_tracer(response):

if g.tracer_span:

g.tracer_span.finish()

return response

return app

开发者ID:CoderHito,项目名称:InfoSub,代码行数:44,

示例3: create_app

​点赞 2

# 需要导入模块: import config [as 别名]

# 或者: from config import app_config [as 别名]

def create_app(config_name):

if os.getenv('FLASK_CONFIG') == "production":

app = Flask(__name__)

app.config.update(

SECRET_KEY=os.getenv('SECRET_KEY'),

SQLALCHEMY_DATABASE_URI=os.getenv('SQLALCHEMY_DATABASE_URI')

)

else:

app = Flask(__name__, instance_relative_config=True)

app.config.from_object(app_config[config_name])

app.config.from_pyfile('config.py')

Bootstrap(app)

db.init_app(app)

login_manager.init_app(app)

login_manager.login_message = "You must be logged in to access this page."

login_manager.login_view = "auth.login"

migrate = Migrate(app, db)

from app import models

from .admin import admin as admin_blueprint

app.register_blueprint(admin_blueprint, url_prefix='/admin')

from .auth import auth as auth_blueprint

app.register_blueprint(auth_blueprint)

from .home import home as home_blueprint

app.register_blueprint(home_blueprint)

@app.errorhandler(403)

def forbidden(error):

return render_template('errors/403.html', title='Forbidden'), 403

@app.errorhandler(404)

def page_not_found(error):

return render_template('errors/404.html', title='Page Not Found'), 404

@app.errorhandler(500)

def internal_server_error(error):

return render_template('errors/500.html', title='Server Error'), 500

return app

开发者ID:mbithenzomo,项目名称:project-dream-team-three,代码行数:45,

示例4: create_app

​点赞 2

# 需要导入模块: import config [as 别名]

# 或者: from config import app_config [as 别名]

def create_app(config_name):

"""

Main app settings

"""

app = Flask(__name__, instance_relative_config=True)

app.config.from_object(app_config[config_name])

app.config.from_pyfile('config.py')

db.init_app(app)

"""

LoginManager settings

"""

login_manager.init_app(app)

login_manager.login_message = "Lutfen uye olunuz."

login_manager.login_view = "uye.giris"

migrate = Migrate(app, db)

Bootstrap(app)

from app import models

from .admin import admin as admin_blueprint

app.register_blueprint(admin_blueprint, url_prefix='/admin')

from .Uye import uye as uye_blueprint

app.register_blueprint(uye_blueprint)

from .home import home as home_blueprint

app.register_blueprint(home_blueprint)

@app.errorhandler(403)

def forbidden(error):

return render_template('errors/Yasak.html', title='Yasak'), 403

@app.errorhandler(404)

def page_not_found(error):

return render_template('errors/404.html', title='Sayfa Bulunamadi'), 404

@app.errorhandler(500)

def internal_server_error(error):

return render_template('errors/500.html', title='Server Hatasi'), 500

return app

开发者ID:Lumenified,项目名称:myapp,代码行数:47,

示例5: create_app

​点赞 2

# 需要导入模块: import config [as 别名]

# 或者: from config import app_config [as 别名]

def create_app(config_name):

"""

Given a configuration name, loads the correct

configuration from the config.py

:param config_name: The configuration name to load the configuration

:return: The app to be initialized

"""

app = Flask(__name__, instance_relative_config=True)

app.config.from_object(app_config[config_name])

app.config.from_pyfile('config.py')

db.init_app(app)

"""

Configurations of the flask-login, in which, if user tries to access a

page that they are not authorized to, it will redirect to the specific

view and display the message below on the route auth.login

"""

login_manager.init_app(app)

login_manager.login_message = "You must be logged in to access this page"

login_manager.login_view = "auth.login"

"""

Migrations setting up.

This object "migrate" will allow us to run migrations using Flask-Migrate.

We also have imported the models from the app package.

"""

migrate = Migrate(app, db)

Bootstrap(app)

"""

Import the models to be used in the application

"""

from app import models

"""

Configuring the blueprints of each package on the app

"""

from .admin import admin as admin_blueprint

# This url_prefix means that all the views for this blueprint will be

# accessed in the browser with the url prefix admin.

app.register_blueprint(admin_blueprint, url_prefix='/admin')

from .auth import auth as auth_blueprint

app.register_blueprint(auth_blueprint)

from .home import home as home_blueprint

app.register_blueprint(home_blueprint)

return app

开发者ID:cpmarx,项目名称:dream-team,代码行数:51,

示例6: create_app

​点赞 2

# 需要导入模块: import config [as 别名]

# 或者: from config import app_config [as 别名]

def create_app(config_name):

app = Flask(__name__, instance_relative_config=True)

app.config.from_object(app_config[config_name])

app.config.from_pyfile('config.py')

Bootstrap(app)

db.init_app(app)

login_manager.init_app(app)

login_manager.login_message = "You must be logged in to access this page."

login_manager.login_view = "auth.login"

migrate = Migrate(app, db)

from app import models

from .admin import admin as admin_blueprint

app.register_blueprint(admin_blueprint, url_prefix='/admin')

from .auth import auth as auth_blueprint

app.register_blueprint(auth_blueprint)

from .home import home as home_blueprint

app.register_blueprint(home_blueprint)

@app.errorhandler(403)

def forbidden(error):

return render_template('errors/403.html', title='Forbidden'), 403

@app.errorhandler(404)

def page_not_found(error):

return render_template('errors/404.html', title='Page Not Found'), 404

@app.errorhandler(500)

def internal_server_error(error):

return render_template('errors/500.html', title='Server Error'), 500

@app.route('/500')

def error():

abort(500)

# @app.route('/')

# def hello_world():

# return 'Hello, World!'

return app

开发者ID:molo76,项目名称:project_dream_team,代码行数:46,

示例7: create_app

​点赞 1

# 需要导入模块: import config [as 别名]

# 或者: from config import app_config [as 别名]

def create_app(config_name):

global user_datastore

app = Flask(__name__)

app.config.from_object(app_config[config_name])

csrf = CSRFProtect()

csrf.init_app(app)

assets = Environment(app)

create_assets(assets)

via = Via()

via.init_app(app)

# Code for desmostration the flask upload in several models - - - -

from user import user_photo

from restaurant import restaurant_photo

from food import food_photo

configure_uploads(app, (restaurant_photo, food_photo, user_photo))

engine = create_engine(app.config['SQLALCHEMY_DATABASE_URI'])

if not database_exists(engine.url):

create_database(engine.url)

security = Security(app, user_datastore, register_form=SecurityRegisterForm)

create_security_admin(app=app, path=os.path.join(os.path.dirname(__file__)))

with app.app_context():

db.init_app(app)

db.create_all()

user_datastore.find_or_create_role(name='admin', description='Administrator')

db.session.commit()

user_datastore.find_or_create_role(name='end-user', description='End user')

db.session.commit()

@app.route('/', methods=['GET'])

@app.route('/home', methods=['GET'])

def index():

return render_template('index.html')

@app.errorhandler(403)

def forbidden(error):

return render_template('error/403.html', title='Forbidden'), 403

@app.errorhandler(404)

def page_not_found(error):

return render_template('error/404.html', title='Page Not Found'), 404

@app.errorhandler(500)

def internal_server_error(error):

db.session.rollback()

return render_template('error/500.html', title='Server Error'), 500

return app

开发者ID:CharlyJazz,项目名称:Flask-MVC-Template,代码行数:60,

注:本文中的config.app_config方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值