Using @login_required without "? Next = /" added to the url

I use the @login_required decorator this way:

@login_required(login_url=reverse_lazy('login'))
def my_view:

Now I know that I can specify the login URL in the settings, but this is not my question. The fact is that after redirecting to my "login" URL, he adds to it ?next=:

http://whatever.com/login/?next=/fakeurl/

I do not want it. Is there a way to override this? Thanks.

+4
source share
1 answer

You can pass an additional parameter redirect_field_name=Noneto login_requireddecorator.

@login_required(login_url=reverse_lazy('login'), redirect_field_name=None)
def my_view(request): ...

This will remove the part ?next=in the url.

+4
source

Source: https://habr.com/ru/post/1626277/


All Articles