本文整理汇总了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)
示例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)
示例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)
示例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
示例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)
示例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))
示例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
示例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()
示例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)
示例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)
示例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))
示例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))
示例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)
示例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)
示例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)