'accounts/logout' isn't working !!

767 views
Skip to first unread message

AshiQul Islam Munna

unread,
Feb 22, 2024, 1:27:24 PM2/22/24
to Django users
Hello!

I am using default auth system in my project these steps-

1. Add this in my project urls path("accounts/", include("django.contrib.auth.urls")), 

2. Create HTML file in  -'templates/registration/login.html'

3. In 'base.html' i wrote -
{% if user.is_authenticated %}
        <p>Hi {{ user.username }}!</p>
        <p><a href="{% url 'logout' %}">Log out</a></p>
        {% else %}
        <p>You are not logged in.</p>
        <a href="{% url 'login' %}">Log In</a>
        {% endif %}

4. And finally in 'setting.py' set 
LOGIN_REDIRECT_URL = "home"
LOGOUT_REDIRECT_URL = "home"

That's ALL!
' LOGIN ' works perfectly but "LOGOUT " not working. It say's-
Screenshot_96.png

Okechukwu Ogo

unread,
Feb 22, 2024, 2:03:03 PM2/22/24
to django...@googlegroups.com
Check your logout URL and view if there's a mistake

--
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 django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c94cea9b-59be-41f3-ae1b-2a7c64156e8fn%40googlegroups.com.

Adisa Habeebulah

unread,
Feb 22, 2024, 3:29:10 PM2/22/24
to django...@googlegroups.com
Remove the LOGOUT_REDIRECT_URL from the settings
That should solve the problem


AshiQul Islam Munna

unread,
Feb 22, 2024, 3:40:25 PM2/22/24
to django...@googlegroups.com
I didn't use custom url, just added auth default url to url in my project 'path("accounts/", include("django.contrib.auth.urls")),and called login, logout url in template.  Login works perfectly but logout does not work.

You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/v2T9gA87vmA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMeYHes6XEoGcHAgLQqgXMPLwkU9dh%2BbV3k0vPcVGU8MEAZGuw%40mail.gmail.com.

AshiQul Islam Munna

unread,
Feb 22, 2024, 3:42:57 PM2/22/24
to django...@googlegroups.com
Tried!  But not worked! 
I find a solution -

Called url in templete with a form and csrf token.

You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/v2T9gA87vmA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAF0%2B-3nghV_jj93v7yHwFuUKp4hfFDjMCNMUyWR1AyZbie6NxA%40mail.gmail.com.

AshiQul Islam Munna

unread,
Feb 22, 2024, 3:44:16 PM2/22/24
to django...@googlegroups.com
Tried!  But not worked! 
I find a solution -

Called logout url in templete with a form and csrf token.

On Thu, 22 Feb 2024, 9:29 pm Adisa Habeebulah, <adisaha...@gmail.com> wrote:
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/v2T9gA87vmA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAF0%2B-3nghV_jj93v7yHwFuUKp4hfFDjMCNMUyWR1AyZbie6NxA%40mail.gmail.com.

Ryan Nowakowski

unread,
Feb 26, 2024, 11:48:02 PM2/26/24
to django...@googlegroups.com
HTTP 405 is method not allowed. What method is in the request to /logout/? You can use your browser's dev tools to view the request.

Ryan Nowakowski

unread,
Feb 26, 2024, 11:54:34 PM2/26/24
to django...@googlegroups.com

Keshav Jha

unread,
Mar 14, 2024, 12:50:02 PM3/14/24
to Django users

New Version of django does not support GET method for logout.

You have two options to accomplish your task:
1. Send a post  request to logout.
2. Custom Manage:
         > Create a custom url in the project's url.py at the top.
              path('admin/logout/', logout_), 
         > Create a view in the project's views.py.
             
def logout_(request):
logout(request)
return redirect('/admin/')
Reply all
Reply to author
Forward
0 new messages