Example #1
0
def find_template_and_decorate(name, dirs=None):
    # Calculate template_source_loaders the first time the function is executed
    # because putting this logic in the module-level namespace may cause
    # circular import errors. See Django ticket #1292.

    from django.template.loader import find_template_loader, make_origin
    from django.template import TemplateDoesNotExist
    global template_source_loaders
    if template_source_loaders is None:
        loaders = []
        for loader_name in settings.TEMPLATE_LOADERS:
            loader = find_template_loader(loader_name)
            if loader is not None:
                loaders.append(loader)
        template_source_loaders = tuple(loaders)
    for loader in template_source_loaders:
        try:
            source, display_name = loader(name, dirs)

            # see if this template has a render method, and if so
            # decorate it to emit signals when rendering happens
            if hasattr(source, 'render'):
                if not hasattr(source.render, 'decorated'):

                    # this class has not been decorated yet...
                    source.__class__.render = render_decorator(
                        source.__class__.render)
                
            return (source, make_origin(display_name, loader, name, dirs))
        except TemplateDoesNotExist:
            pass
    raise TemplateDoesNotExist(name)
Example #2
0
 def get_frame_CNN(self, loader):
     image = numpy.transpose(self.frame, (2, 0, 1))
     image = Image.fromarray(self.frame)
     image = loader(image).float()
     image = Variable(image, requires_grad=True)
     image = image.unsqueeze(0)
     image = to_device(image, device)
     return image
Example #3
0
 def find_template(self, name):
     for loader in template_source_loaders:
         if not isinstance(loader, Jinja2Loader):
             continue
         try:
             #NOT THREAD SAFE
             loader.skip_dirs_original = loader.skip_dirs
             loader.skip_dirs = []
             template = loader(name, None)[0]
             if hasattr(template, 'render'):
                 return template
         except TemplateDoesNotExist:
             pass
         finally:
             loader.skip_dirs = loader.skip_dirs_original
     raise TemplateDoesNotExist()
Example #4
0
def index(request):
    template = loader('index.html')
    context = {}
    return HttpResponse("index")