You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

locmem.py 673B

5 years ago
123456789101112131415161718192021222324252627
  1. """
  2. Wrapper for loading templates from a plain Python dict.
  3. """
  4. from django.template import Origin, TemplateDoesNotExist
  5. from .base import Loader as BaseLoader
  6. class Loader(BaseLoader):
  7. def __init__(self, engine, templates_dict):
  8. self.templates_dict = templates_dict
  9. super().__init__(engine)
  10. def get_contents(self, origin):
  11. try:
  12. return self.templates_dict[origin.name]
  13. except KeyError:
  14. raise TemplateDoesNotExist(origin)
  15. def get_template_sources(self, template_name):
  16. yield Origin(
  17. name=template_name,
  18. template_name=template_name,
  19. loader=self,
  20. )