pythonwsgiwsgiref

How to pass arguments to wsgiref application in Python?


A wsgiref application function has to look as follows:

def application(environ, start_response):

start_response is just a function, while environ does not have any parameters set by the user (https://www.python.org/dev/peps/pep-3333/#environ-variables).
Given this, how could user-defined variables be used by the application without making them global?


Solution

  • Figured it out. the application function can be part of a class, allowing for self to be taken as an argument. The class can hold any data which will be needed by the application.

    class XYZ:
        def application(self, environ, start_response):