本文整理汇总了Python中django.views.decorators.csrf.ensure_csrf_cookie方法的典型用法代码示例。如果您正苦于以下问题:Python csrf.ensure_csrf_cookie方法的具体用法?Python csrf.ensure_csrf_cookie怎么用?Python csrf.ensure_csrf_cookie使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.views.decorators.csrf
的用法示例。
在下文中一共展示了csrf.ensure_csrf_cookie方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: help_page
# 需要导入模块: from django.views.decorators import csrf [as 别名]
# 或者: from django.views.decorators.csrf import ensure_csrf_cookie [as 别名]
def help_page(request, page_name):
request.page_title = page_name
try:
return render_to_response("dashboard/help/" + page_name.replace('-', '_').lower() + ".html",
{'request': request})
except Exception as e:
logger.error(e)
return error_404(request)
# 如果html页面的表单中没有{%csrftoken%},
# django 就不会自动设置csrf token的cookie
# 需要ensure_csrf_cookie,来强制添加
示例2: get_ui_urlpatterns
# 需要导入模块: from django.views.decorators import csrf [as 别名]
# 或者: from django.views.decorators.csrf import ensure_csrf_cookie [as 别名]
def get_ui_urlpatterns(ui_urlpatterns):
return [
re_path(pattern, ensure_csrf_cookie(IndexView.as_view()), name="index",)
for pattern in ui_urlpatterns
]
示例3: get
# 需要导入模块: from django.views.decorators import csrf [as 别名]
# 或者: from django.views.decorators.csrf import ensure_csrf_cookie [as 别名]
def get(self, request, *args, **kwargs):
""" Introduces the ``ensure_csrf_cookie`` decorator and handles xeditable choices ajax. """
if request.GET.get(self.xeditable_fieldname_param):
return self.get_ajax_xeditable_choices(request, *args, **kwargs)
# Doing this in the method body at runtime instead of at declaration-time helps prevent
# collisions of other subclasses also trying to decorate their own get() methods.
method = super(XEditableMixin, self).get
method = ensure_csrf_cookie(method)
return method(request, *args, **kwargs)