当前位置: 首页>>代码示例>>Python>>正文


Python TemplateResponse.xframe_options_exempt方法代码示例

本文整理汇总了Python中django.template.response.TemplateResponse.xframe_options_exempt方法的典型用法代码示例。如果您正苦于以下问题:Python TemplateResponse.xframe_options_exempt方法的具体用法?Python TemplateResponse.xframe_options_exempt怎么用?Python TemplateResponse.xframe_options_exempt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.template.response.TemplateResponse的用法示例。


在下文中一共展示了TemplateResponse.xframe_options_exempt方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: render_article

# 需要导入模块: from django.template.response import TemplateResponse [as 别名]
# 或者: from django.template.response.TemplateResponse import xframe_options_exempt [as 别名]
def render_article(request, article, current_language, slug):
    """
    Renders an article
    """
    context = {}
    context['article'] = article
    context['lang'] = current_language
    context['current_article'] = article
    context['has_change_permissions'] = article.has_change_permission(request)

    response = TemplateResponse(request, article.template, context)
    response.add_post_render_callback(set_page_cache)

    # Add headers for X Frame Options - this really should be changed upon moving to class based views
    xframe_options = article.tree.get_xframe_options()
    # xframe_options can be None if there's no xframe information on the page
    # (eg. a top-level page which has xframe options set to "inherit")
    if xframe_options == Page.X_FRAME_OPTIONS_INHERIT or xframe_options is None:
        # This is when we defer to django's own clickjacking handling
        return response

    # We want to prevent django setting this in their middlewear
    response.xframe_options_exempt = True

    if xframe_options == Page.X_FRAME_OPTIONS_ALLOW:
        # Do nothing, allowed is no header.
        return response
    elif xframe_options == Page.X_FRAME_OPTIONS_SAMEORIGIN:
        response['X-Frame-Options'] = 'SAMEORIGIN'
    elif xframe_options == Page.X_FRAME_OPTIONS_DENY:
        response['X-Frame-Options'] = 'DENY'
    return response
开发者ID:misli,项目名称:django-cms-articles,代码行数:34,代码来源:article_rendering.py

示例2: render_page

# 需要导入模块: from django.template.response import TemplateResponse [as 别名]
# 或者: from django.template.response.TemplateResponse import xframe_options_exempt [as 别名]
def render_page(request, page, current_language, slug):
    """
    Renders a page
    """
    template_name = get_template_from_request(request, page, no_current_page=True)
    # fill the context
    context = {}
    context["lang"] = current_language
    context["current_page"] = page
    context["has_change_permissions"] = user_can_change_page(request.user, page)
    context["has_view_permissions"] = user_can_view_page(request.user, page)

    if not context["has_view_permissions"]:
        return _handle_no_page(request, slug)

    response = TemplateResponse(request, template_name, context)
    response.add_post_render_callback(set_page_cache)

    # Add headers for X Frame Options - this really should be changed upon moving to class based views
    xframe_options = page.get_xframe_options()
    # xframe_options can be None if there's no xframe information on the page
    # (eg. a top-level page which has xframe options set to "inherit")
    if xframe_options == Page.X_FRAME_OPTIONS_INHERIT or xframe_options is None:
        # This is when we defer to django's own clickjacking handling
        return response

    # We want to prevent django setting this in their middlewear
    response.xframe_options_exempt = True

    if xframe_options == Page.X_FRAME_OPTIONS_ALLOW:
        # Do nothing, allowed is no header.
        return response
    elif xframe_options == Page.X_FRAME_OPTIONS_SAMEORIGIN:
        response["X-Frame-Options"] = "SAMEORIGIN"
    elif xframe_options == Page.X_FRAME_OPTIONS_DENY:
        response["X-Frame-Options"] = "DENY"
    return response
开发者ID:nimbis,项目名称:django-cms,代码行数:39,代码来源:page_rendering.py


注:本文中的django.template.response.TemplateResponse.xframe_options_exempt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。