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


Python csrf.requires_csrf_token方法代碼示例

本文整理匯總了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 %}. 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:19,代碼來源:defaults.py

示例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 %}. 
開發者ID:mozilla,項目名稱:telemetry-analysis-service,代碼行數:23,代碼來源:views.py

示例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 %}. 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:23,代碼來源:defaults.py

示例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 %}. 
開發者ID:django-leonardo,項目名稱:django-leonardo,代碼行數:25,代碼來源:defaults.py

示例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 %}. 
開發者ID:Yeah-Kun,項目名稱:python,代碼行數:23,代碼來源:defaults.py

示例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 %}. 
開發者ID:blackye,項目名稱:luscan-devel,代碼行數:19,代碼來源:defaults.py

示例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 %}. 
開發者ID:drexly,項目名稱:openhgsenti,代碼行數:20,代碼來源:defaults.py

示例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 %}. 
開發者ID:django-leonardo,項目名稱:django-leonardo,代碼行數:9,代碼來源:defaults.py

示例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) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:9,代碼來源:tests.py


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