def _should_abort(request, allowed_methods, **kwargs):
ajax_only = kwargs.get('ajax_only', True)
should_redirect = False if ajax_only else True
# abort if user is not valid
should_abort = _should_abort_user(request, should_redirect)
if should_abort:
return should_abort
# only accept AJAX requests
if not request.is_ajax() and kwargs.get('ajax_only', True):
return HttpResponse(status=422)
# only accept certain methods
if isinstance(allowed_methods, str):
allowed_methods = [allowed_methods]
if request.method not in allowed_methods:
return HttpResponseNotAllowed(allowed_methods)
return None
评论列表
文章目录