本文整理匯總了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)