[Fixed]-Django form dispatch method : value error : view returned None instead of HttpResponse

1๐Ÿ‘

โœ…

As @Daniel Roseman mentioned in his comment below your question. If user is not authenticated then inner does not return any response whereas it should return redirect_to_login('/admin/') in that case.

So changing

def inner(request, *args, **kwargs):
    user = request.user
    if user.is_authenticated():
        if (user.groups.filter(name__in=group_names) and user.is_staff) or user.is_superuser:
            return func(request, *args, **kwargs)
        return redirect_to_login('/admin/')

to

def inner(request, *args, **kwargs):
    user = request.user
    if user.is_authenticated():
        if (user.groups.filter(name__in=group_names) and user.is_staff) or user.is_superuser:
            return func(request, *args, **kwargs)
    return redirect_to_login('/admin/')

should resolve the issue. See the difference return redirect_to_login('/admin/') is outside the if block.

๐Ÿ‘คMuhammad Tahir

Leave a comment