Python django.views.decorators.csrf.ensure_csrf_cookie() Examples
The following are 3
code examples of django.views.decorators.csrf.ensure_csrf_cookie().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.views.decorators.csrf
, or try the search function
.
Example #1
Source File: views.py From fomalhaut-panel with MIT License | 5 votes |
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,来强制添加
Example #2
Source File: __init__.py From polyaxon with Apache License 2.0 | 5 votes |
def get_ui_urlpatterns(ui_urlpatterns): return [ re_path(pattern, ensure_csrf_cookie(IndexView.as_view()), name="index",) for pattern in ui_urlpatterns ]
Example #3
Source File: xeditable.py From sal with Apache License 2.0 | 5 votes |
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)