本文整理匯總了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)