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


Python csrf.csrf_exempt方法代码示例

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


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

示例1: provider_for_django

# 需要导入模块: from django.views.decorators import csrf [as 别名]
# 或者: from django.views.decorators.csrf import csrf_exempt [as 别名]
def provider_for_django(provider):
    def provider_view(request):
        def get_header(key, default):
            django_key = 'HTTP_%s' % key.upper().replace('-', '_')
            return request.META.get(django_key, default)
        method = request.method
        # Compatible with low version Django
        try:
            signed_data = request.raw_post_data
        except AttributeError:
            signed_data = request.body
        # if getattr(request, 'body', None):
        #     signed_data = request.body
        # else:
        #     signed_data = request.raw_post_data
        status_code, data = provider.get_response(
            method,
            signed_data,
            get_header,
        )
        return HttpResponse(data, status=status_code)
    return csrf_exempt(provider_view) 
开发者ID:forcemain,项目名称:notes,代码行数:24,代码来源:sync.py

示例2: fix_initial_order

# 需要导入模块: from django.views.decorators import csrf [as 别名]
# 或者: from django.views.decorators.csrf import csrf_exempt [as 别名]
def fix_initial_order(self, initial_order):
        """
        "initial_order" is a list of (position, direction) tuples; for example:
            [[1, 'asc'], [5, 'desc']]

        Here, we also accept positions expressed as column names,
        and convert the to the corresponding numeric position.
        """
        values = []
        keys = list(self.column_index.keys())
        for position, direction in initial_order:
            if type(position) == str:
                position = keys.index(position)
            values.append([position, direction])
        return values

    #@method_decorator(csrf_exempt) 
开发者ID:morlandi,项目名称:django-datatables-view,代码行数:19,代码来源:views.py

示例3: as_view

# 需要导入模块: from django.views.decorators import csrf [as 别名]
# 或者: from django.views.decorators.csrf import csrf_exempt [as 别名]
def as_view(cls, **initkwargs):
        """
        Store the original class on the view function.
        This allows us to discover information about the view when we do URL
        reverse lookups.  Used for breadcrumb generation.
        """
        if isinstance(getattr(cls, 'queryset', None), models.query.QuerySet):
            def force_evaluation():
                raise RuntimeError(
                    'Do not evaluate the `.queryset` attribute directly, '
                    'as the result will be cached and reused between requests. '
                    'Use `.all()` or call `.get_queryset()` instead.'
                )
            cls.queryset._fetch_all = force_evaluation

        view = super(APIView, cls).as_view(**initkwargs)
        view.cls = cls
        view.initkwargs = initkwargs

        # Note: session based authentication is explicitly CSRF validated,
        # all other authentication is CSRF exempt.
        return csrf_exempt(view) 
开发者ID:BeanWei,项目名称:Dailyfresh-B2C,代码行数:24,代码来源:views.py

示例4: cached_api

# 需要导入模块: from django.views.decorators import csrf [as 别名]
# 或者: from django.views.decorators.csrf import csrf_exempt [as 别名]
def cached_api(*args, **kwargs):
    """
    Only works on API endpoints with csrf_exempt=True and public_jsonp=False.
    """
    def decorator(func):
        kwargs['request_gatekeeper'] = lambda request: not getattr(cached_view, 'never_cache', False)
        kwargs['response_gatekeeper'] = _response_gatekeeper

        def response_wrapper(ret):
            ret = loads(ret)
            ret['success'] = True
            ret = client_dumps(ret)
            return HttpResponse(ret, 'application/json')

        cache_func = cached_view(*args,
                                 cached_response_wrapper=response_wrapper,
                                 serializer=client_dumps,
                                 **kwargs)(func)
        cache_func.arg_spec = ArgSpec(func)

        return cache_func
    return decorator 
开发者ID:canvasnetworks,项目名称:canvas,代码行数:24,代码来源:api_cache.py

示例5: as_view

# 需要导入模块: from django.views.decorators import csrf [as 别名]
# 或者: from django.views.decorators.csrf import csrf_exempt [as 别名]
def as_view(cls, **initkwargs):
        view = super(BaseRouteView, cls).as_view(**initkwargs)
        view.cls = cls
        view.initkwargs = initkwargs
        return csrf_exempt(view) 
开发者ID:jet-admin,项目名称:jet-bridge,代码行数:7,代码来源:route_view.py

示例6: as_view

# 需要导入模块: from django.views.decorators import csrf [as 别名]
# 或者: from django.views.decorators.csrf import csrf_exempt [as 别名]
def as_view(cls, *args, **kwargs):
        return csrf_exempt(super().as_view(*args, **kwargs)) 
开发者ID:chaoss,项目名称:prospector,代码行数:4,代码来源:feedback.py

示例7: as_view

# 需要导入模块: from django.views.decorators import csrf [as 别名]
# 或者: from django.views.decorators.csrf import csrf_exempt [as 别名]
def as_view(cls, *args, **kwargs):
        view = super(ExtraGraphQLView, cls).as_view(*args, **kwargs)
        view = csrf_exempt(view)
        return view 
开发者ID:eamigo86,项目名称:graphene-django-extras,代码行数:6,代码来源:views.py

示例8: service_rpc

# 需要导入模块: from django.views.decorators import csrf [as 别名]
# 或者: from django.views.decorators.csrf import csrf_exempt [as 别名]
def service_rpc(request, username, repository):
    """
        Responds to 'git-receive-pack' or 'git-upload-pack' requests
            for the given username and repository.
        Decorator 'csrf_exempt' is used because git POST requests does not provide csrf cookies and
            therefore validation cannot be done.
    """

    requested_repo = Repo(Repo.get_repository_location(username, repository))
    response = GitResponse(service=request.path_info.split('/')[-1], action=GIT_ACTION_RESULT,
                    repository=requested_repo, data=request.body)

    return response.get_http_service_rpc() 
开发者ID:Djacket,项目名称:djacket,代码行数:15,代码来源:views.py

示例9: dispatch

# 需要导入模块: from django.views.decorators import csrf [as 别名]
# 或者: from django.views.decorators.csrf import csrf_exempt [as 别名]
def dispatch(self, *args, **kwargs):  # pylint: disable=arguments-differ
        """
        Request needs to be csrf_exempt to handle POST back from external payment processor.
        """
        return super(CancelCheckoutView, self).dispatch(*args, **kwargs) 
开发者ID:edx,项目名称:ecommerce,代码行数:7,代码来源:views.py

示例10: as_view

# 需要导入模块: from django.views.decorators import csrf [as 别名]
# 或者: from django.views.decorators.csrf import csrf_exempt [as 别名]
def as_view(cls, **initkwargs):
        view = super(CSRFExemptMixin, cls).as_view(**initkwargs)
        return csrf_exempt(view) 
开发者ID:pythonindia,项目名称:junction,代码行数:5,代码来源:views.py

示例11: as_list

# 需要导入模块: from django.views.decorators import csrf [as 别名]
# 或者: from django.views.decorators.csrf import csrf_exempt [as 别名]
def as_list(self, *args, **kwargs):
        return csrf_exempt(super(DjangoResource, self).as_list(*args, **kwargs)) 
开发者ID:toastdriven,项目名称:restless,代码行数:4,代码来源:dj.py

示例12: as_detail

# 需要导入模块: from django.views.decorators import csrf [as 别名]
# 或者: from django.views.decorators.csrf import csrf_exempt [as 别名]
def as_detail(self, *args, **kwargs):
        return csrf_exempt(super(DjangoResource, self).as_detail(*args, **kwargs)) 
开发者ID:toastdriven,项目名称:restless,代码行数:4,代码来源:dj.py

示例13: test_process_request_csrf_cookie_no_token_exempt_view

# 需要导入模块: from django.views.decorators import csrf [as 别名]
# 或者: from django.views.decorators.csrf import csrf_exempt [as 别名]
def test_process_request_csrf_cookie_no_token_exempt_view(self):
        """
        If a CSRF cookie is present and no token, but the csrf_exempt decorator
        has been applied to the view, the middleware lets it through
        """
        req = self._get_POST_csrf_cookie_request()
        self.mw.process_request(req)
        req2 = self.mw.process_view(req, csrf_exempt(post_form_view), (), {})
        self.assertIsNone(req2) 
开发者ID:nesdis,项目名称:djongo,代码行数:11,代码来源:tests.py

示例14: test_get_token_for_exempt_view

# 需要导入模块: from django.views.decorators import csrf [as 别名]
# 或者: from django.views.decorators.csrf import csrf_exempt [as 别名]
def test_get_token_for_exempt_view(self):
        """
        get_token still works for a view decorated with 'csrf_exempt'.
        """
        req = self._get_GET_csrf_cookie_request()
        self.mw.process_request(req)
        self.mw.process_view(req, csrf_exempt(token_view), (), {})
        resp = token_view(req)
        self._check_token_present(resp) 
开发者ID:nesdis,项目名称:djongo,代码行数:11,代码来源:tests.py

示例15: as_view

# 需要导入模块: from django.views.decorators import csrf [as 别名]
# 或者: from django.views.decorators.csrf import csrf_exempt [as 别名]
def as_view(cls, **init_kwargs):
        """
        Store the original class on the view function.

        This allows us to discover information about the view when we do URL
        reverse lookups.  Used for breadcrumb generation.
        """
        view = super(View, cls).as_view(**init_kwargs)
        view.cls = cls
        # Note: session based authentication is explicitly CSRF validated,
        # all other authentication is CSRF exempt.
        return csrf_exempt(view) 
开发者ID:erigones,项目名称:esdc-ce,代码行数:14,代码来源:views.py


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