views.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:valentina 作者: valentinavc 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号