本文整理汇总了Python中django.template.exceptions.TemplateDoesNotExist方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.TemplateDoesNotExist方法的具体用法?Python exceptions.TemplateDoesNotExist怎么用?Python exceptions.TemplateDoesNotExist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.template.exceptions
的用法示例。
在下文中一共展示了exceptions.TemplateDoesNotExist方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _validate_template_name_existence
# 需要导入模块: from django.template import exceptions [as 别名]
# 或者: from django.template.exceptions import TemplateDoesNotExist [as 别名]
def _validate_template_name_existence(template_name):
try:
get_template(template_name)
except TemplateDoesNotExist:
raise ImproperlyConfigured(
'Template {template_name!r} does not exists'.format(
template_name=template_name))
示例2: ServerError
# 需要导入模块: from django.template import exceptions [as 别名]
# 或者: from django.template.exceptions import TemplateDoesNotExist [as 别名]
def ServerError(request, template_name=ERROR_500_TEMPLATE_NAME):
"""
Custom 500 handler to provide details when rendering 500.html.
"""
try:
template = loader.get_template(template_name)
except TemplateDoesNotExist:
return HttpResponseServerError(
"<h1>Server Error (500)</h1>", content_type="text/html"
)
type_, error, _ = sys.exc_info()
return HttpResponseServerError(
template.render({"exception": str(type_), "error": error})
)
示例3: find_template_file
# 需要导入模块: from django.template import exceptions [as 别名]
# 或者: from django.template.exceptions import TemplateDoesNotExist [as 别名]
def find_template_file(template_name):
"""
Return a full path to the specified template file.
The key difference from the stock `find_template` is that we don't try to
load a template in memory, because we'll deal with it ourselves.
"""
for loader in _get_template_loaders():
for origin in loader.get_template_sources(template_name, None):
path = getattr(origin, 'name', origin) # Django <1.9 compatibility
if os.path.exists(path):
return path
raise TemplateDoesNotExist(template_name)
示例4: test_server_error
# 需要导入模块: from django.template import exceptions [as 别名]
# 或者: from django.template.exceptions import TemplateDoesNotExist [as 别名]
def test_server_error(rf):
request = rf.get("/")
response = server_error(request)
assert response.status_code == 500
with pytest.raises(TemplateDoesNotExist):
server_error(request, template_name="non-existing.html")
示例5: test_wtm_include_marketing
# 需要导入模块: from django.template import exceptions [as 别名]
# 或者: from django.template.exceptions import TemplateDoesNotExist [as 别名]
def test_wtm_include_marketing(rf, site):
token = Token(token_type=TOKEN_TYPE, contents='wtm_include "marketing" "test.html"')
parser = Parser(tokens=[token])
node = wtm_include(parser, token)
with pytest.raises(TemplateDoesNotExist):
request = rf.get(site.root_page.url)
node.render(context=make_context({"request": request}))
request.COOKIES = {"wtm": "marketing:false"}
node.render(context=make_context({"request": request}))
request.COOKIES = {"wtm": "marketing:true"}
node.render(context=make_context({"request": request}))
示例6: common
# 需要导入模块: from django.template import exceptions [as 别名]
# 或者: from django.template.exceptions import TemplateDoesNotExist [as 别名]
def common(request):
if request.is_ajax() or hasattr(request, 'versioning_scheme'):
return {}
from apps.extract.app_vars import STANDARD_LOCATORS, OPTIONAL_LOCATORS
available_locators = set(STANDARD_LOCATORS.val) | set(OPTIONAL_LOCATORS.val)
custom_main_menu_item_templates = []
custom_task_menu_item_templates = []
custom_apps = [i.replace('apps.', '') for i in settings.INSTALLED_APPS if i.startswith('apps.')]
for app_name in custom_apps:
try:
mmi_template = get_template('%s/templates/%s' % (app_name, 'main_menu_item.html'))
custom_main_menu_item_templates.append(mmi_template.template.name)
except TemplateDoesNotExist:
pass
try:
tmi_template = get_template('%s/templates/%s' % (app_name, 'task_menu_item.html'))
custom_task_menu_item_templates.append(tmi_template.template.name)
except TemplateDoesNotExist:
pass
return {'settings': settings,
'custom_main_menu_item_templates': custom_main_menu_item_templates,
'custom_task_menu_item_templates': custom_task_menu_item_templates,
'available_locators': available_locators}