find_template.py 695 B

12345678910111213141516171819202122
  1. # -*- coding: utf-8 -*-
  2. import sys
  3. from django.core.management.base import LabelCommand
  4. from django.template import TemplateDoesNotExist, loader
  5. from django_extensions.management.utils import signalcommand
  6. class Command(LabelCommand):
  7. help = "Finds the location of the given template by resolving its path"
  8. args = "[template_path]"
  9. label = 'template path'
  10. @signalcommand
  11. def handle_label(self, template_path, **options):
  12. try:
  13. template = loader.get_template(template_path).template
  14. except TemplateDoesNotExist:
  15. sys.stderr.write("No template found\n")
  16. else:
  17. sys.stdout.write(self.style.SUCCESS((template.name)))