本文整理匯總了Python中django.views.decorators.csrf.requires_csrf_token方法的典型用法代碼示例。如果您正苦於以下問題:Python csrf.requires_csrf_token方法的具體用法?Python csrf.requires_csrf_token怎麽用?Python csrf.requires_csrf_token使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.views.decorators.csrf
的用法示例。
在下文中一共展示了csrf.requires_csrf_token方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: bad_request
# 需要導入模塊: from django.views.decorators import csrf [as 別名]
# 或者: from django.views.decorators.csrf import requires_csrf_token [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 %}.
示例2: server_error
# 需要導入模塊: from django.views.decorators import csrf [as 別名]
# 或者: from django.views.decorators.csrf import requires_csrf_token [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 %}.
示例3: bad_request
# 需要導入模塊: from django.views.decorators import csrf [as 別名]
# 或者: from django.views.decorators.csrf import requires_csrf_token [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 %}.
示例4: bad_request
# 需要導入模塊: from django.views.decorators import csrf [as 別名]
# 或者: from django.views.decorators.csrf import requires_csrf_token [as 別名]
def bad_request(request, template_name='400.html'):
"""
400 error handler.
Templates: :template:`400.html`
Context: None
"""
response = render_in_page(request, template_name)
if response:
return response
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(Context({})))
# This can be called when CsrfViewMiddleware.process_view has not run,
# therefore need @requires_csrf_token in case the template needs
# {% csrf_token %}.
示例5: bad_request
# 需要導入模塊: from django.views.decorators import csrf [as 別名]
# 或者: from django.views.decorators.csrf import requires_csrf_token [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 http.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 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 %}.
示例6: server_error
# 需要導入模塊: from django.views.decorators import csrf [as 別名]
# 或者: from django.views.decorators.csrf import requires_csrf_token [as 別名]
def server_error(request, template_name='500.html'):
"""
500 error handler.
Templates: :template:`500.html`
Context: None
"""
try:
template = loader.get_template(template_name)
except TemplateDoesNotExist:
return http.HttpResponseServerError('<h1>Server Error (500)</h1>')
return http.HttpResponseServerError(template.render(Context({})))
# This can be called when CsrfViewMiddleware.process_view has not run,
# therefore need @requires_csrf_token in case the template needs
# {% csrf_token %}.
示例7: bad_request
# 需要導入模塊: from django.views.decorators import csrf [as 別名]
# 或者: from django.views.decorators.csrf import requires_csrf_token [as 別名]
def bad_request(request, exception, 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')
# No exception content is passed to the template, to not disclose any sensitive information.
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 %}.
示例8: trigger_error
# 需要導入模塊: from django.views.decorators import csrf [as 別名]
# 或者: from django.views.decorators.csrf import requires_csrf_token [as 別名]
def trigger_error(request):
raise VerifySentryServerError
# This can be called when CsrfViewMiddleware.process_view has not run,
# therefore need @requires_csrf_token in case the template needs
# {% csrf_token %}.
示例9: test_get_token_for_requires_csrf_token_view
# 需要導入模塊: from django.views.decorators import csrf [as 別名]
# 或者: from django.views.decorators.csrf import requires_csrf_token [as 別名]
def test_get_token_for_requires_csrf_token_view(self):
"""
get_token() works for a view decorated solely with requires_csrf_token.
"""
req = self._get_GET_csrf_cookie_request()
resp = requires_csrf_token(token_view)(req)
self._check_token_present(resp)