Arguments to web.py handler classes

不想你离开。 提交于 2019-12-23 09:32:04

问题


Is there any way to pass arguments to web.py handler class constructors?

E.g. These arguments might come from the command line (when the main web.py script is run), after the first arg (which is taken as the port number)


回答1:


Sure, depending on exactly what you mean. It's all python after all.

Consider you have available web.config which is a Storage object which is visible everywhere. I regularly use that to place system-wide configuration information (& alter debugging output as you'll see in the example).

Being a Storage object, you can add your own configuration items there & then access them in your url handlers.

if __name__ == '__main__':
    app = web.application(urls, globals())
    web.config.debug_sql = '--debug_sql' in sys.argv
    app.run()


来源:https://stackoverflow.com/questions/10683968/arguments-to-web-py-handler-classes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!