[Answer]-Django Redirect the Logout Process to a View

1πŸ‘

To logout use POST instead of GET. It is a architecture issue.
So to logout you should make a post request like the following example.

Logout template form

<form action="{% url 'logout' %}" method="post" >
  {% csrf_token %}
  <input type="submit" value="Logout" />
</form>

Logout url

urlpatterns = patterns('',
    url(r'^logout/$', LogoutView.as_view(), name='logout'),
    # other urls...
)

Logout view

from django.contrib.auth import logout

class LogoutView(ProcessFormView):
    def post(self, request, *args, **kwargs):
        logout(request)
        return redirect('login-url-name')
πŸ‘€Rhemzo

0πŸ‘

Example logout

@require_POST
def logout(request):
    auth.logout(request)
    return redirect('/')
πŸ‘€rebelius

Leave a comment