[Python] When I log out, I get a blank page - Django 5

Discussão em 'Python' iniciado por Stack, Dezembro 1, 2024.

  1. Stack

    Stack Membro Participativo

    So when I want to log out the user it shows a white blank page at http://127.0.0.1:8000/accounts/logout/

    I'm using the shortcut way to redirect to next page in settings.py and I tested to logout with admin panel and it works fine.

    settings.py

    ...

    LOGIN_REDIRECT_URL = 'index'

    LOGOUT_REDIRECT_URL = 'index'

    ...


    this is my urls.py:

    from django.contrib import admin
    from django.urls import path,include

    urlpatterns = [
    path('admin/', admin.site.urls),
    path('',include('post.urls')),
    path('accounts/', include('django.contrib.auth.urls') ),
    ]


    This is how I login:

    login.html:

    {% extends "base.html" %}

    {% block content %}

    <div class="container">
    <h1> LOGIN FORM </h1>
    <form method="post">
    {% csrf_token %}
    {{form.as_p}}
    <button type="submit" class= "btn btn-success">Log In</button>
    </form>
    </div>
    <br>
    {% endblock content %}


    base.html:

    ...
    <ul>
    <li><a class="active " href="{% url 'index' %}">Home</a></li>
    <li><a class="active " href="{% url 'about' %}">About</a></li>
    {% if user.is_authenticated %}
    <li><a class="active " href="{% url 'logout' %}">Log Out</a></li>
    {% else %}
    <li><a class="active " href="{% url 'login' %}">Log In</a></li>
    {% endif %}
    </ul>

    ...


    and for log out all I did was the 'href="{% url 'logout' %}"' in base.html as far as I learned there is no code needed in views.py. .what am I missing?

    Continue reading...

Compartilhe esta Página