當前位置: 首頁>>代碼示例>>Python>>正文


Python csrf.csrf_protect方法代碼示例

本文整理匯總了Python中django.views.decorators.csrf.csrf_protect方法的典型用法代碼示例。如果您正苦於以下問題:Python csrf.csrf_protect方法的具體用法?Python csrf.csrf_protect怎麽用?Python csrf.csrf_protect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.views.decorators.csrf的用法示例。


在下文中一共展示了csrf.csrf_protect方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: password_reset_done

# 需要導入模塊: from django.views.decorators import csrf [as 別名]
# 或者: from django.views.decorators.csrf import csrf_protect [as 別名]
def password_reset_done(request,
                        template_name='registration/password_reset_done.html',
                        current_app=None, extra_context=None):
    context = {
        'title': _('Password reset sent'),
    }
    if extra_context is not None:
        context.update(extra_context)

    if current_app is not None:
        request.current_app = current_app

    return TemplateResponse(request, template_name, context)


# Doesn't need csrf_protect since no-one can guess the URL 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:18,代碼來源:views.py

示例2: password_reset_done

# 需要導入模塊: from django.views.decorators import csrf [as 別名]
# 或者: from django.views.decorators.csrf import csrf_protect [as 別名]
def password_reset_done(request,
                        template_name='registration/password_reset_done.html',
                        extra_context=None):
    warnings.warn("The password_reset_done() view is superseded by the "
                  "class-based PasswordResetDoneView().",
                  RemovedInDjango21Warning, stacklevel=2)
    context = {
        'title': _('Password reset sent'),
    }
    if extra_context is not None:
        context.update(extra_context)

    return TemplateResponse(request, template_name, context)


# Doesn't need csrf_protect since no-one can guess the URL 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:18,代碼來源:views.py

示例3: create_admin

# 需要導入模塊: from django.views.decorators import csrf [as 別名]
# 或者: from django.views.decorators.csrf import csrf_protect [as 別名]
def create_admin(request):
    """
    網站剛開始運行時,沒有管理員,需要創建一個
    :param request:
    :return:
    """
    if SiteUser.has_admin():
        return error_404(request)
    else:
        request.page_title = '創建管理員'
        return render_to_response('accounts/create_admin.html', {'request': request})
        # 使用 context_instance=RequestContext(request) 會出現問題
        # Model class django.contrib.auth.models. Permission doesn't declare an explicit app_label and either
        # isn't in an application in INSTALLED_APPS or else was imported before its application was loaded.
        # return render_to_response('accounts/create_admin.html', {'request': request},
        #                            context_instance=RequestContext(request))
        # 解決csrf_protect不能工作,在前端不能顯示csrf_token
        # 加上context_instance=RequestContext(request) 
開發者ID:restran,項目名稱:fomalhaut-panel,代碼行數:20,代碼來源:views.py

示例4: password_reset_done

# 需要導入模塊: from django.views.decorators import csrf [as 別名]
# 或者: from django.views.decorators.csrf import csrf_protect [as 別名]
def password_reset_done(request,
                        template_name='registration/password_reset_done.html',
                        extra_context=None):
    context = {
        'title': _('Password reset sent'),
    }
    if extra_context is not None:
        context.update(extra_context)

    return TemplateResponse(request, template_name, context)


# Doesn't need csrf_protect since no-one can guess the URL 
開發者ID:drexly,項目名稱:openhgsenti,代碼行數:15,代碼來源:views.py

示例5: password_reset_done

# 需要導入模塊: from django.views.decorators import csrf [as 別名]
# 或者: from django.views.decorators.csrf import csrf_protect [as 別名]
def password_reset_done(request,
                        template_name='registration/password_reset_done.html',
                        extra_context=None):
  context = {
    'title': _('Password reset sent'),
  }
  if extra_context is not None:
    context.update(extra_context)

  return TemplateResponse(request, template_name, context)


# Doesn't need csrf_protect since no-one can guess the URL 
開發者ID:F0RE1GNERS,項目名稱:eoj3,代碼行數:15,代碼來源:auth_view.py

示例6: admin_view

# 需要導入模塊: from django.views.decorators import csrf [as 別名]
# 或者: from django.views.decorators.csrf import csrf_protect [as 別名]
def admin_view(self, view, cacheable=False):
        """
        Decorator to create an admin view attached to this ``AdminSite``. This
        wraps the view and provides permission checking by calling
        ``self.has_permission``.

        You'll want to use this from within ``AdminSite.get_urls()``:

            class MyAdminSite(AdminSite):

                def get_urls(self):
                    from django.conf.urls import url

                    urls = super(MyAdminSite, self).get_urls()
                    urls += [
                        url(r'^my_view/$', self.admin_view(some_view))
                    ]
                    return urls

        By default, admin_views are marked non-cacheable using the
        ``never_cache`` decorator. If the view can be safely cached, set
        cacheable=True.
        """
        def inner(request, *args, **kwargs):
            if not self.has_permission(request):
                if request.path == reverse('admin:logout', current_app=self.name):
                    index_path = reverse('admin:index', current_app=self.name)
                    return HttpResponseRedirect(index_path)
                # Inner import to prevent django.contrib.admin (app) from
                # importing django.contrib.auth.models.User (unrelated model).
                from django.contrib.auth.views import redirect_to_login
                return redirect_to_login(
                    request.get_full_path(),
                    reverse('admin:login', current_app=self.name)
                )
            return view(request, *args, **kwargs)
        if not cacheable:
            inner = never_cache(inner)
        # We add csrf_protect here so this function can be used as a utility
        # function for any view, without having to repeat 'csrf_protect'.
        if not getattr(view, 'csrf_exempt', False):
            inner = csrf_protect(inner)
        return update_wrapper(inner, view) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:45,代碼來源:sites.py

示例7: admin_view

# 需要導入模塊: from django.views.decorators import csrf [as 別名]
# 或者: from django.views.decorators.csrf import csrf_protect [as 別名]
def admin_view(self, view, cacheable=False):
        """
        Decorator to create an admin view attached to this ``AdminSite``. This
        wraps the view and provides permission checking by calling
        ``self.has_permission``.

        You'll want to use this from within ``AdminSite.get_urls()``:

            class MyAdminSite(AdminSite):

                def get_urls(self):
                    from django.urls import path

                    urls = super().get_urls()
                    urls += [
                        path('my_view/', self.admin_view(some_view))
                    ]
                    return urls

        By default, admin_views are marked non-cacheable using the
        ``never_cache`` decorator. If the view can be safely cached, set
        cacheable=True.
        """
        def inner(request, *args, **kwargs):
            if not self.has_permission(request):
                if request.path == reverse('admin:logout', current_app=self.name):
                    index_path = reverse('admin:index', current_app=self.name)
                    return HttpResponseRedirect(index_path)
                # Inner import to prevent django.contrib.admin (app) from
                # importing django.contrib.auth.models.User (unrelated model).
                from django.contrib.auth.views import redirect_to_login
                return redirect_to_login(
                    request.get_full_path(),
                    reverse('admin:login', current_app=self.name)
                )
            return view(request, *args, **kwargs)
        if not cacheable:
            inner = never_cache(inner)
        # We add csrf_protect here so this function can be used as a utility
        # function for any view, without having to repeat 'csrf_protect'.
        if not getattr(view, 'csrf_exempt', False):
            inner = csrf_protect(inner)
        return update_wrapper(inner, view) 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:45,代碼來源:sites.py

示例8: admin_view

# 需要導入模塊: from django.views.decorators import csrf [as 別名]
# 或者: from django.views.decorators.csrf import csrf_protect [as 別名]
def admin_view(self, view, cacheable=False):
    """
    Decorator to create an admin view attached to this ``AdminSite``. This
    wraps the view and provides permission checking by calling
    ``self.has_permission``.

    You'll want to use this from within ``AdminSite.get_urls()``:

        class MyAdminSite(AdminSite):

            def get_urls(self):
                from django.conf.urls import url

                urls = super(MyAdminSite, self).get_urls()
                urls += [
                    url(r'^my_view/$', self.admin_view(some_view))
                ]
                return urls

    By default, admin_views are marked non-cacheable using the
    ``never_cache`` decorator. If the view can be safely cached, set
    cacheable=True.
    """
    def inner(request, *args, **kwargs):
        if not self.has_permission(request):
            if request.path == reverse('admin:logout', current_app=self.name):
                index_path = reverse('admin:index', current_app=self.name)
                return HttpResponseRedirect(URL_PREFIX_RESOURCE + index_path)
            # Inner import to prevent django.contrib.admin (app) from
            # importing django.contrib.auth.models.User (unrelated model).
            from django.contrib.auth.views import redirect_to_login
            return redirect_to_login(
                request.get_full_path(),
                reverse('admin:login', current_app=self.name)
            )
        return view(request, *args, **kwargs)
    if not cacheable:
        inner = never_cache(inner)
    # We add csrf_protect here so this function can be used as a utility
    # function for any view, without having to repeat 'csrf_protect'.
    if not getattr(view, 'csrf_exempt', False):
        inner = csrf_protect(inner)
    return update_wrapper(inner, view) 
開發者ID:texta-tk,項目名稱:texta,代碼行數:45,代碼來源:admin.py


注:本文中的django.views.decorators.csrf.csrf_protect方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。