Guest User

Untitled

a guest
Jan 21st, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. def render_string(self, template_name, **kwargs):
  2. """Generate the given template with the given arguments.
  3.  
  4. We return the generated string. To generate and write a template
  5. as a response, use render() above.
  6. """
  7. # If no template_path is specified, use the path of the calling file
  8. template_path = self.get_template_path()
  9. if not template_path:
  10. frame = sys._getframe(0)
  11. web_file = frame.f_code.co_filename
  12. while frame.f_code.co_filename == web_file:
  13. frame = frame.f_back
  14. template_path = os.path.dirname(frame.f_code.co_filename)
  15. with RequestHandler._template_loader_lock:
  16. if template_path not in RequestHandler._template_loaders:
  17. loader = self.create_template_loader(template_path)
  18. RequestHandler._template_loaders[template_path] = loader
  19. else:
  20. loader = RequestHandler._template_loaders[template_path]
  21. t = loader.load(template_name)
  22. args = dict(
  23. handler=self,
  24. request=self.request,
  25. current_user=self.current_user,
  26. locale=self.locale,
  27. _=self.locale.translate,
  28. static_url=self.static_url,
  29. xsrf_form_html=self.xsrf_form_html,
  30. reverse_url=self.application.reverse_url
  31. )
  32. args.update(self.ui)
  33. args.update(kwargs)
  34. return t.generate(**args)
Add Comment
Please, Sign In to add comment