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 context_processor to help me solve this problem.

There are several ways to achieve this.

The easiest way is probably to look like this:

  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))   

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:

  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))   

There are other ways to:

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -