金字塔模板总是在刷新时在 Openshift 服务器上重新加载(烹饪)



我在Openshift上构建了Python 3.3 Pyramid 1.5应用程序。

在我的本地开发系统上,当我刷新页面时,模板只会在我启动服务器后重新加载(烹饪)一次。在生产服务器(Openshift)上,每次刷新页面时,模板总是重新加载(烹饪)。 模板未更改,因此不应重新加载。

"reload_templates"配置变量在开发和生产 ini 文件中都设置为"false"。请参阅下面的配置。

知道为什么模板总是在我的 Openshift 应用程序上的页面刷新时重新加载(烹饪)吗?

我的开发.ini和生产.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)

初始化.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

一种可能性:

环境变量和.ini文件设置

如果存在与环境变量

含义相同的配置文件设置,并且两者在应用程序启动时都存在,则环境变量设置优先。

我也不确定对.ini设置使用--reload的优先级。 您使用什么命令来启动服务器?

问题是我如何在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)

最新更新