I'm following a tutorial in the Python Crash Course book on creating a simple web page using Django. I've just created an app to log a user in and out on my page, using Django's default user authentication system. When I logout, Django is not redirecting to the template I've created to show that the user is logged out. Instead it redirects to the Django admin logout page.
Here is my base urls.py file.
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('users/', include('users.urls')),
path('', include('learning_logs.urls')),
]
Here is my 'users' app urls.py file.
from django.urls import path, include
app_name = 'users'
urlpatterns = [
# Include default auth URLs
path('', include('django.contrib.auth.urls')),
]
Here is my base.html template.
<p>
<a href="{% url 'learning_logs:index' %}">Learning Log</a> -
<a href="{% url 'learning_logs:topics' %}">Topics</a>
{% if user.is_authenticated %}
Hello, {{ user.username }}.
<a href="{% url 'users:logout' %}">Log out</a>
{% else %}
<a href="{% url 'users:login' %}">Log in</a>
{% endif %}
</p>
Here is my logout.html template.
{% extends "learning_logs/base.html" %}
{% block content %}
<p>You have been logged out. Thanks for stopping by!</p>
{% endblock content %}
Here are my installed apps in settings.py
INSTALLED_APPS = [
# My Apps
'learning_logs',
'users',
# Default Apps
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
When the page redirects to the Django Admin logout, the url shows up as http://localhost:8000/users/logout/ which is the url I want. Also, I am using my admin username and password to login to the web page.
Any help is appreciated!
edit: Django version being used is 3.2.6. Version being used in the tutorial is 2.2