当前位置: 首页>>代码示例>>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;未经允许,请勿转载。