File: find_template.py

package info (click to toggle)
python-django-extensions 4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 2,820 kB
  • sloc: python: 18,601; javascript: 7,354; makefile: 108; xml: 17
file content (22 lines) | stat: -rw-r--r-- 695 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# -*- coding: utf-8 -*-
import sys

from django.core.management.base import LabelCommand
from django.template import TemplateDoesNotExist, loader

from django_extensions.management.utils import signalcommand


class Command(LabelCommand):
    help = "Finds the location of the given template by resolving its path"
    args = "[template_path]"
    label = "template path"

    @signalcommand
    def handle_label(self, template_path, **options):
        try:
            template = loader.get_template(template_path).template
        except TemplateDoesNotExist:
            sys.stderr.write("No template found\n")
        else:
            sys.stdout.write(self.style.SUCCESS((template.name)))