Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use objects global to the application in requests #149

Open
setop opened this issue Apr 6, 2022 · 0 comments
Open

use objects global to the application in requests #149

setop opened this issue Apr 6, 2022 · 0 comments

Comments

@setop
Copy link

setop commented Apr 6, 2022

Recently, I've struggled a bit to find a way to initialize an object at application level and use it at request level.

Following an answer to the same question on SO, I finally used web.config.

It looks like this:

class Foo:
	def GET(self):
		bar = web.config.bar
		r = bar.something()
		return r

if __name__ == "__main__":
	web.config.bar = Bar()
	app = web.application(urls, globals())
	app.run()

I don't know if it the right way to do it. Nevertheless, IMHO, this use case should be documented in the very usefull "cookbook" section. And web.config should be documented in "API Reference" section.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant