class Tester(object):
def __init__(self):
self.environ=environ
def __call__(self, environ, startResponse):
startResponse("200 OK", [("Content-Type", "text/plain")])
ApplicationName=self.environ['mod_wsgi.process_group']
return ["Application name: {}".format(ApplicationName)]
application=Tester()
I get:
NameError: global name 'environ' is not defined
How do I get environ inside __init__?
-- Gnarlie
You need to give the class as an object as the application and not an
instance of it:
class Tester(object):
def __init__(self, environ, start_response):
self.environ=environ
start_response("200 OK", [("Content-Type", "text/plain")])
def __iter__(self):
application_name = self.environ['mod_wsgi.process_group']
yield "Application name: {}".format(application_name)
application=Tester
That's because mod_wsgi calls the application from global scope with the
two arguments: environ and start_response. With your code it would call
the __call__ method, but you yourself called the __init__ with no args. In
my code I give the class type itself as application, so the __init__
method gets called by mod_wsgi, which then expects the iterable content to
be returned, so the class instance itself should be that iterable, hence
the output in __iter__ method.
I hope that clarified it a bit.
--
You received this message because you are subscribed to the Google Groups
"modwsgi" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/modwsgi?hl=en.