我已经在Openshift上构建了Python3.3金字塔1.5应用程序。
在我的本地开发系统上,当我刷新页面时,模板只能在启动服务器后重新加载一次。在生产服务器(Openshift)上,每次刷新页面时,模板总是重新加载(厨师)。模板没有更改,因此不应该重新加载。
在开发和生产ini文件中,“reload_templates”配置变量都被设置为“false”。请参见下面的配置。
知道为什么模板总是在我的Openshift应用程序的页面刷新中重新加载(厨师)吗?
我的development.ini和production.ini都设置为以下设置。
pyramid.reload_templates = false
pyramid.debug_authorization = false
pyramid.debug_notfound = false
pyramid.debug_routematch = false
pyramid.default_locale_name = en
编辑:这里是我如何启动我的金字塔应用程序的Openshift (跟随他们的基本启动)
app.py在OPENSHIFT服务器启动时启动
app.py
if __name__ == '__main__':
import imp
ip = os.environ['OPENSHIFT_PYTHON_IP']
port = int(os.environ['OPENSHIFT_PYTHON_PORT'])
zapp = imp.load_source('main_production_no_pserve', 'myapp/__init__.py')
print('Starting Waitress Server on %s:%d ... ' % (ip, port))
run_waitress(zapp.main_production_no_pserve, ip, port)
init.py
def main_production_no_pserve(environ, start_response):
settings = {
'pyramid.reload_templates': 'false',
'pyramid.debug_authorization': 'false',
'pyramid.debug_notfound': 'false',
'pyramid.debug_routematch': 'false',
'pyramid.default_locale_name': 'en'
}
config = app_configuration(settings)
app = config.make_wsgi_app()(environ, start_response)
return app
def app_configuration(settings):
config = Configurator(authentication_policy=authentication_policy,
authorization_policy=authorization_policy,
settings=settings)
config.include('pyramid_chameleon')
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('Home_View', '/')
config.add_subscriber('subscribers.handle_my_response','pyramid.events.NewResponse')
config.set_request_factory(myrequest)
config.scan('myapp.views')
return config
发布于 2014-01-22 10:48:07
问题是我是如何在Openshift上启动服务器的。旧的方法给人一种工作的错觉,但从长远来看确实没有。新代码如下:
def main_production_no_pserve (global_config, **settings):
settings = {
'pyramid.reload_templates': 'true',
'pyramid.debug_authorization': 'false',
'pyramid.debug_notfound': 'false',
'pyramid.debug_routematch': 'false',
'pyramid.default_locale_name': 'en'
}
config = app_configuration(settings)
app = config.make_wsgi_app()
return app
if __name__ == '__main__':
ip = os.environ['OPENSHIFT_PYTHON_IP']
port = int(os.environ['OPENSHIFT_PYTHON_PORT'])
app = main_production_no_pserve(global_config=None)
from waitress import serve
serve(app, host=ip, port=port, threads=50)
发布于 2014-01-15 17:54:09
一种可能性是:
如果配置文件设置与环境变量的含义相同,并且在应用程序启动时都存在,则环境变量设置优先。
此外,我也不确定对--reload
设置使用.ini
设置的优先级。您使用什么命令来启动服务器?
https://stackoverflow.com/questions/21151332
复制