google app engine - webapp2 jinja2 context_processor -
I am creating a project on GAE, webapp2, jinja2 and I use it for authorization. To use sessions with users from webapp2.request in templates, I want something like Django's There are several ways to achieve this. The easiest way is probably to look like this: I like when my variable templates are in Global, then I can access them in templates widgets without having to surround the surround wires, From: There are other ways to: context_processor to help me solve this problem.
def extra_context (handler, context = none): "" adds additional context. " Loaded from settings like "reference = context or {} #degego" and running different template processors # I do not do this in my projects because I am not yet creating another framework # so I like to keep it simple: return Dict ({'request': handler.}}, ** references) # --- Somewhere handler in response --- get DF (self): my_context = {} template = get_template_somehow () self.response.out.write ( Template .Redder (** extra_context (auto, my_cont Ext))
def get_template_globals (handler): return {'request': handler. Request, 'Settings': & lt; ... & gt;} class MyHandlerBase (webapp. RequestHandler): def render (self, reference = none): reference = context or {} globals_ = get_template_globals (self) template = jinja_env.get_template (template_ Name, globals = globals_) self.response.out.write (template.reader (** reference))
Comments
Post a Comment