當前位置: 首頁>>代碼示例>>Python>>正文


Python template.TemplateDoesNotExist方法代碼示例

本文整理匯總了Python中django.template.TemplateDoesNotExist方法的典型用法代碼示例。如果您正苦於以下問題:Python template.TemplateDoesNotExist方法的具體用法?Python template.TemplateDoesNotExist怎麽用?Python template.TemplateDoesNotExist使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.template的用法示例。


在下文中一共展示了template.TemplateDoesNotExist方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: setUp

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import TemplateDoesNotExist [as 別名]
def setUp(self):
        super(TestMMVHTMLRenderer, self).setUp()

        """
        Monkeypatch get_template
        Taken from DRF Tests
        """
        self.get_template = django.template.loader.get_template

        def get_template(template_name, dirs=None):
            if template_name == 'test.html':
                return engines['django'].from_string("<html>test: {{ data }}</html>")
            raise TemplateDoesNotExist(template_name)

        def select_template(template_name_list, dirs=None, using=None):
            if template_name_list == ['test.html']:
                return engines['django'].from_string("<html>test: {{ data }}</html>")
            raise TemplateDoesNotExist(template_name_list[0])

        django.template.loader.get_template = get_template
        django.template.loader.select_template = select_template 
開發者ID:MattBroach,項目名稱:DjangoRestMultipleModels,代碼行數:23,代碼來源:test_html_renderer.py

示例2: render

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import TemplateDoesNotExist [as 別名]
def render(self, render_type, context):
        """
        Renders the template

        :param render_type: the content type to render
        :param context: context data dictionary
        :return: the rendered content
        """

        assert render_type in self.render_types, 'Invalid Render Type'

        try:
            content = render_to_string('herald/{}/{}.{}'.format(
                render_type,
                self.template_name,
                'txt' if render_type == 'text' else render_type
            ), context)
        except TemplateDoesNotExist:
            content = None

            if settings.DEBUG:
                raise

        return content 
開發者ID:worthwhile,項目名稱:django-herald,代碼行數:26,代碼來源:base.py

示例3: page_not_found

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import TemplateDoesNotExist [as 別名]
def page_not_found(request, template_name='404.html'):
    """
    Default 404 handler.

    Templates: :template:`404.html`
    Context:
        request_path
            The path of the requested URL (e.g., '/app/pages/bad_page/')
    """
    context = {'request_path': request.path}
    try:
        template = loader.get_template(template_name)
        body = template.render(context, request)
        content_type = None             # Django will use DEFAULT_CONTENT_TYPE
    except TemplateDoesNotExist:
        template = Engine().from_string(
            '<h1>Not Found</h1>'
            '<p>The requested URL {{ request_path }} was not found on this server.</p>')
        body = template.render(Context(context))
        content_type = 'text/html'
    return http.HttpResponseNotFound(body, content_type=content_type) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:23,代碼來源:defaults.py

示例4: bad_request

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import TemplateDoesNotExist [as 別名]
def bad_request(request, template_name='400.html'):
    """
    400 error handler.

    Templates: :template:`400.html`
    Context: None
    """
    try:
        template = loader.get_template(template_name)
    except TemplateDoesNotExist:
        return http.HttpResponseBadRequest('<h1>Bad Request (400)</h1>', content_type='text/html')
    return http.HttpResponseBadRequest(template.render())


# This can be called when CsrfViewMiddleware.process_view has not run,
# therefore need @requires_csrf_token in case the template needs
# {% csrf_token %}. 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:19,代碼來源:defaults.py

示例5: directory_index

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import TemplateDoesNotExist [as 別名]
def directory_index(path, fullpath):
    try:
        t = loader.select_template([
            'static/directory_index.html',
            'static/directory_index',
        ])
    except TemplateDoesNotExist:
        t = Engine().from_string(DEFAULT_DIRECTORY_INDEX_TEMPLATE)
    files = []
    for f in os.listdir(fullpath):
        if not f.startswith('.'):
            if os.path.isdir(os.path.join(fullpath, f)):
                f += '/'
            files.append(f)
    c = Context({
        'directory': path + '/',
        'file_list': files,
    })
    return HttpResponse(t.render(c)) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:21,代碼來源:static.py

示例6: server_error

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import TemplateDoesNotExist [as 別名]
def server_error(request, template_name=ERROR_500_TEMPLATE_NAME):
    """
    500 error handler.

    :template: :file:`500.html`
    """
    try:
        template = loader.get_template(template_name)
    except TemplateDoesNotExist:
        if template_name != ERROR_500_TEMPLATE_NAME:
            # Reraise if it's a missing custom template.
            raise
        return http.HttpResponseServerError(
            "<h1>Server Error (500)</h1>", content_type="text/html"
        )
    return http.HttpResponseServerError(template.render(request=request))


# This can be called when CsrfViewMiddleware.process_view has not run,
# therefore need @requires_csrf_token in case the template needs
# {% csrf_token %}. 
開發者ID:mozilla,項目名稱:telemetry-analysis-service,代碼行數:23,代碼來源:views.py

示例7: permission_denied

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import TemplateDoesNotExist [as 別名]
def permission_denied(request, exception, template_name=ERROR_403_TEMPLATE_NAME):
    """
    Permission denied (403) handler.

    :template: :file:`403.html`

    If the template does not exist, an Http403 response containing the text
    "403 Forbidden" (as per RFC 7231) will be returned.
    """
    try:
        template = loader.get_template(template_name)
    except TemplateDoesNotExist:
        if template_name != ERROR_403_TEMPLATE_NAME:
            # Reraise if it's a missing custom template.
            raise
        return http.HttpResponseForbidden(
            "<h1>403 Forbidden</h1>", content_type="text/html"
        )
    return http.HttpResponseForbidden(
        template.render(request=request, context={"exception": force_text(exception)})
    ) 
開發者ID:mozilla,項目名稱:telemetry-analysis-service,代碼行數:23,代碼來源:views.py

示例8: bad_request

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import TemplateDoesNotExist [as 別名]
def bad_request(request, exception, template_name=ERROR_400_TEMPLATE_NAME):
    """
    400 error handler.

    Templates: :template:`400.html`
    Context: None
    """
    try:
        template = loader.get_template(template_name)
    except TemplateDoesNotExist:
        if template_name != ERROR_400_TEMPLATE_NAME:
            # Reraise if it's a missing custom template.
            raise
        return HttpResponseBadRequest('<h1>Bad Request (400)</h1>', content_type='text/html')
    # No exception content is passed to the template, to not disclose any sensitive information.
    return HttpResponseBadRequest(template.render())


# This can be called when CsrfViewMiddleware.process_view has not run,
# therefore need @requires_csrf_token in case the template needs
# {% csrf_token %}. 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:23,代碼來源:defaults.py

示例9: permission_denied

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import TemplateDoesNotExist [as 別名]
def permission_denied(request, exception, template_name=ERROR_403_TEMPLATE_NAME):
    """
    Permission denied (403) handler.

    Templates: :template:`403.html`
    Context: None

    If the template does not exist, an Http403 response containing the text
    "403 Forbidden" (as per RFC 7231) will be returned.
    """
    try:
        template = loader.get_template(template_name)
    except TemplateDoesNotExist:
        if template_name != ERROR_403_TEMPLATE_NAME:
            # Reraise if it's a missing custom template.
            raise
        return HttpResponseForbidden('<h1>403 Forbidden</h1>', content_type='text/html')
    return HttpResponseForbidden(
        template.render(request=request, context={'exception': str(exception)})
    ) 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:22,代碼來源:defaults.py

示例10: directory_index

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import TemplateDoesNotExist [as 別名]
def directory_index(path, fullpath):
    try:
        t = loader.select_template([
            'static/directory_index.html',
            'static/directory_index',
        ])
    except TemplateDoesNotExist:
        t = Engine(libraries={'i18n': 'django.templatetags.i18n'}).from_string(DEFAULT_DIRECTORY_INDEX_TEMPLATE)
        c = Context()
    else:
        c = {}
    files = []
    for f in os.listdir(fullpath):
        if not f.startswith('.'):
            if os.path.isdir(os.path.join(fullpath, f)):
                f += '/'
            files.append(f)
    c.update({
        'directory': path + '/',
        'file_list': files,
    })
    return HttpResponse(t.render(c)) 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:24,代碼來源:static.py

示例11: get_template

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import TemplateDoesNotExist [as 別名]
def get_template(self, template_name, skip=None):
        """
        Call self.get_template_sources() and return a Template object for
        the first template matching template_name. If skip is provided, ignore
        template origins in skip. This is used to avoid recursion during
        template extending.
        """
        tried = []

        for origin in self.get_template_sources(template_name):
            if skip is not None and origin in skip:
                tried.append((origin, 'Skipped'))
                continue

            try:
                contents = self.get_contents(origin)
            except TemplateDoesNotExist:
                tried.append((origin, 'Source does not exist'))
                continue
            else:
                return Template(
                    contents, origin, origin.template_name, self.engine,
                )

        raise TemplateDoesNotExist(template_name, tried=tried) 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:27,代碼來源:base.py

示例12: entry_point

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import TemplateDoesNotExist [as 別名]
def entry_point(context, block_name):
    """include an snippet at the bottom of a block, if it exists

    For example, if the plugin with slug 'attachments' is registered

       waliki/attachments_edit_content.html  will be included with

        {% entry_point 'edit_content' %}

    which is declared at the bottom of the block 'content' in edit.html
    """
    from waliki.plugins import get_plugins
    includes = []
    for plugin in get_plugins():
        template_name = 'waliki/%s_%s.html' % (plugin.slug, block_name)
        try:
            # template exists
            template.loader.get_template(template_name)
            includes.append(template_name)
        except template.TemplateDoesNotExist:
            continue
    context.update({'includes': includes})
    return context 
開發者ID:mgaitan,項目名稱:waliki,代碼行數:25,代碼來源:waliki_tags.py

示例13: approval_status_changed

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import TemplateDoesNotExist [as 別名]
def approval_status_changed(obj, request, **kwargs):
    get_recipients = {
        obj.PENDING: obj.get_approver_email_list,
        obj.WITHDRAWN: obj.get_approver_email_list,
        obj.APPROVED: obj.get_submitter_email_list,
        obj.REJECTED: obj.get_submitter_email_list,
    }[obj.approval_status]

    # produces template names like "home/email/project-pending.txt"
    template = "{}/email/{}-{}.txt".format(
            obj._meta.app_label,
            obj._meta.model_name,
            obj.get_approval_status_display().lower())

    try:
        send_template_mail(template, {
                obj._meta.model_name: obj,
            },
            request=request,
            recipient_list=get_recipients(),
            **kwargs)
    except TemplateDoesNotExist:
        logger.info(
            "not sending approval status change email because %s does not exist",
            template, exc_info=True) 
開發者ID:outreachy,項目名稱:website,代碼行數:27,代碼來源:email.py

示例14: show_includes

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import TemplateDoesNotExist [as 別名]
def show_includes(template_path, seen, depth=0):
    if template_path in seen:
        return
    print("  " * depth + template_path)
    seen.add(template_path)

    try:
        template = loader.get_template(template_path).template
    except TemplateDoesNotExist:
        print("  " * depth + "*** previous template not found!")
        return

    for included in re.findall(r"{%\s*include\s+([^\s]*)[^%]*%}", template.source):
        if included[0] in "\"'":
            show_includes(included[1:-1], seen, depth + 1)
        else:
            print("  " * (depth + 1) + "*** template name given by expression:", repr(included)) 
開發者ID:outreachy,項目名稱:website,代碼行數:19,代碼來源:template_includes.py

示例15: directory_index

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import TemplateDoesNotExist [as 別名]
def directory_index(path, fullpath):
    try:
        t = loader.select_template([
            'static/directory_index.html',
            'static/directory_index',
        ])
    except TemplateDoesNotExist:
        t = Engine(libraries={'i18n': 'django.templatetags.i18n'}).from_string(DEFAULT_DIRECTORY_INDEX_TEMPLATE)
        c = Context()
    else:
        c = {}
    files = []
    for f in fullpath.iterdir():
        if not f.name.startswith('.'):
            url = str(f.relative_to(fullpath))
            if f.is_dir():
                url += '/'
            files.append(url)
    c.update({
        'directory': path + '/',
        'file_list': files,
    })
    return HttpResponse(t.render(c)) 
開發者ID:PacktPublishing,項目名稱:Hands-On-Application-Development-with-PyCharm,代碼行數:25,代碼來源:static.py


注:本文中的django.template.TemplateDoesNotExist方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。