Skip to content

use objects global to the application in requests #149

Description

@setop

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions