本文整理汇总了Python中django.views.defaults.page_not_found方法的典型用法代码示例。如果您正苦于以下问题:Python defaults.page_not_found方法的具体用法?Python defaults.page_not_found怎么用?Python defaults.page_not_found使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.views.defaults
的用法示例。
在下文中一共展示了defaults.page_not_found方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: display_custom_404
# 需要导入模块: from django.views import defaults [as 别名]
# 或者: from django.views.defaults import page_not_found [as 别名]
def display_custom_404(view_func):
@functools.wraps(view_func)
def wrapper(request, *args, **kwargs):
try:
return view_func(request, *args, **kwargs)
except Http404:
return page_not_found(request, '', template_name='wagtailadmin/404.html')
return wrapper
示例2: debug_page_not_found
# 需要导入模块: from django.views import defaults [as 别名]
# 或者: from django.views.defaults import page_not_found [as 别名]
def debug_page_not_found(request):
return defaults.page_not_found(request, AttributeError('foobar'))
示例3: handle404
# 需要导入模块: from django.views import defaults [as 别名]
# 或者: from django.views.defaults import page_not_found [as 别名]
def handle404(request):
if 'application/json' in request.META.get('HTTP_ACCEPT', ''):
return HttpResponse(json.dumps(handlers.NOT_FOUND_JSON_RESPONSE),
status=status.HTTP_404_NOT_FOUND,
content_type='application/json')
if django_version < LooseVersion('1.9'):
return defaults.page_not_found(request)
else:
exc_class, exc, tb = sys.exc_info()
return defaults.page_not_found(request, exc)
示例4: page_not_found
# 需要导入模块: from django.views import defaults [as 别名]
# 或者: from django.views.defaults import page_not_found [as 别名]
def page_not_found(request, exception=None, template_name='apply/404.html'):
if not request.user.is_authenticated:
template_name = '404.html'
return defaults.page_not_found(request, exception, template_name)
示例5: page_not_found
# 需要导入模块: from django.views import defaults [as 别名]
# 或者: from django.views.defaults import page_not_found [as 别名]
def page_not_found(request):
"""
Custom 404 handler.
"""
if request.path.startswith('/api/'):
return HttpResponseNotFound('Resource not found', content_type='application/json')
return defaults.page_not_found(request)