On Oct 7, 2008, at 5:01 PM, EricHolmberg wrote:

>
> How can I create the global c variable that is used in the templates
> if I'm in an WSGI app and not in a controller response method?
>
> With the WSGI dispatch, I need to rewrite some of the output using
> Genshi, so I have the following code:
>
> class EmbeddedtracController(BaseController):
>
>    def __init__(self):
>        # set application to the trac WSGI dispatch_request function
>        self.app = dispatch_request
>        self.trac_env_path = config['trac_env_path']
>
>    def __call__(self, environ, start_response):
>        """Dispatches request to trac."""
> ...
>            self.rewriteLoginPage(environ, strHtml)
> ...
>    def _rewriteLoginPage(self, environ, strHtml):
>        """Handles the 403 Forbidden response."""
>
>        # Set variables for Genshi
>        c.input = strHtml
> ...
>        return render("genshi", "TracLogin")


Probably the best place for calling _rewriteLoginPage would in a  
__before__ method. __call__ is the main entry point into Controllers,  
and unfortunately by that point variables like c aren't setup yet.  
Whereas they would be in __before__ (and __after__).

> which results in the following error message:
>
>  c.input = strHtml
> File 'c:\\python25\\lib\\site-packages\\paste-1.7.1-py2.5.egg\\paste\
> \registry.py', line 140 in __setattr__
>  setattr(self._current_obj(), attr, value)
> File 'c:\\python25\\lib\\site-packages\\paste-1.7.1-py2.5.egg\\paste\
> \registry.py', line 194 in _current_obj
>  'thread' % self.____name__)
> TypeError: No object (name: C) has been registered for this thread

--
Philip Jenvey



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" 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/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to