简体   繁体   中英

How to override python pyramid app config settings?

I am a newbie at Python Pyramid and working on improving an existing app that we have. I have an app main function defined like below:

def web_main(global_config, **settings):
  config = Configurator(settings=settings, root_factory=RootFactory)
  ...
  ...
  config.add_request_method(get_user, "user", reify=True)
  config.set_authentication_policy(authn_policy)
  config.set_authorization_policy(authz_policy)
  ...
  app = config.make_wsgi_app()
  return app

I want to override get_user request method with my implementation and also want to use my own authentication policy.

With that I was thinking to do write a function like below:

def my_web_main(global_config, **settings):
  app = web_main(global_config, **settings)
  <Set Overrides here>
  return app

Inside the config.ini file I will call my_web_main to start this app.

I have not been able to figure out how to set the overrides. Would appreciate some inputs on this.

The configurator is where you should perform overrides. So the answer is to modify web_main or define your own. Pyramid has an override mechanism via config.include() , but it does not work one level higher where you're attempting to override things with a built wsgi-app. You have to do it at the config level.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM