2013-10-08 106 views
0

使用這個Flask bootstrap project,我想指定必須在瓶創建對象定義參數(如template_folder,static_url_path和static_path)初始化後可以更改`template_folder`嗎?

下面的代碼的起始部分:

app_name = app_name or __name__ 
app = Flask(app_name) 

config = config_str_to_obj(config) 
configure_app(app, config) 
configure_logger(app, config) 
configure_blueprints(app, blueprints or config.BLUEPRINTS) 
configure_error_handlers(app) 
configure_database(app) 
configure_context_processors(app) 
configure_template_filters(app) 
configure_extensions(app) 
configure_before_request(app) 
configure_views(app) 

return app 

但是沒有辦法指定之前指出的參數。

我該如何做到這一點,而不用在這個方法中寫入它們(例如使用Config對象)。

回答

2

你可能會改變其中的一些,但Flask並沒有被設計來處理應用程序創建後在應用程序上改變它們。只是看一些代碼,例如,static route is created in the constructor of the Flask application

因此,您需要在構建時設置這些參數。好消息是,您的配置通常以非常容易加載的方式完成(例如,在python模塊中)。您應該可以將自舉程序更改爲:

app_name = app_name or __name__ 

config = config_str_to_obj(config) 
app = Flask(app_name, static_url_path=config.SOME_CONFIGURATION_NAME) 

configure_app(app, config) 
... 
相關問題