Use the logout facility
https://docs.djangoproject.com/en/4.1/topics/auth/default/#how-to-log-a-user-out

from django.contrib.auth import logout

def logout_view(request):
    logout(request)
    # Redirect to a success page.

Abdul Qoyyuum Bin Haji Abdul Kadir
System Engineer at Card Access Services
HP: +673 720 8043

On Mon, Jul 18, 2022, 12:59 AM אורי <[email protected]> wrote:

> Hi,
>
> Log out via GET requests is deprecated from Django 4.1 and will be removed
> in Django 5.0. I have a view where the user has to be logged in (otherwise
> it redirects to login), and then I check if the user logged in is not the
> correct user, and if they are different - I redirect the user to logout
> (via GET), which should then be redirected again to login, and then
> redirected to the same view:
>
> from django.views import generic
> from django.views.generic.detail import SingleObjectMixin
> from rules.contrib.views import LoginRequiredMixin, PermissionRequiredMixin
>
> class VerifyUserEmailAddressView(LoginRequiredMixin, SingleObjectMixin,
> generic.View):
> ...
>     def get(self, request, *args, **kwargs):
>         email_address = self.get_object()
>         if (not (email_address.user == self.request.user)):
>             return
> redirect(to='{}?next={}'.format(reverse('accounts:logout'),
> self.request.get_full_path()))
>         assert (email_address.user == self.request.user)
> ...
>
> Now, what should I do instead of redirecting the user to logout view? How
> do I implement it with POST?
>
> Thanks,
> אורי
> [email protected]
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CABD5YeE0c%2B17cUgiU2tLp7L0zFjEfTVmJ6B3KvkwEftvGsuQBw%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CABD5YeE0c%2B17cUgiU2tLp7L0zFjEfTVmJ6B3KvkwEftvGsuQBw%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA3DN%3DWjhN8Mqx56%3DwvDHJ1S-kQcDh5kVTBrvh2-1qLigeyFWw%40mail.gmail.com.

Reply via email to