I am following a tutorial by Corey Schafer on YouTube. Part 7 Login and Logout System. My register.html works fine. The login.html also works fine. But when I try to logout using 127.0.0.1:8000/logout, I get a blank page. Even when I check the page source it is blank. Here is the register.html file
{% extends "zacsBlog/base.html" %}
{% load crispy_forms_tags %}
{% block content %}
<div class="content-section">
<form method="POST">
{% csrf_token %}
<fieldset class="form-group">
<legend class="border-bottom mb-4">Join Today</legend>
{{ form|crispy }}
<!-- {{ form.as_p }} -->
</fieldset>
<div class="form-group">
<button class="btn btn-outline-info" type="submit">Sign Up</button>
</div>
</form>
<div class="border-top pt-3">
<small class="text-muted">
Already Have An Account? <a class="ml-2" href="{% url 'login' %}">Sign In</a>
</small>
</div>
</div>
{% endblock content %}
Then the login.html file
{% extends "zacsBlog/base.html" %}
{% load crispy_forms_tags %}
{% block content %}
<div class="content-section">
<form action="{% url 'blog-home' %}" method="POST">
{% csrf_token %}
<fieldset class="form-group">
<legend class="border-bottom mb-4">Log In</legend>
{{ form|crispy }}
<!-- {{ form.as_p }} -->
</fieldset>
<div class="form-group">
<button class="btn btn-outline-info" type="submit">Login</button>
</div>
</form>
<div class="border-top pt-3">
<small class="text-muted">
Don't Have An Account? Create An Account Here? <a class="ml-2" href="{% url 'register' %}">Sign Up Now</a>
</small>
</div>
</div>
{% endblock content %}
the logout.html file:-
{% extends “zacsBlog/base.html” %}
{% block content %}
You have been logged out
{% endblock content %}
This is my views.py file
from django.shortcuts import render, redirect
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth import logout
from django.contrib.auth.views import LogoutView
from django.contrib import messages
from .forms import UserRegisterForm
Create your views here.
def register(request):
if request.method == ‘POST’:
form = UserRegisterForm(request.POST)
if form.is_valid():
form.save()
username = form.cleaned_data.get(‘username’)
messages.success(request, f’Your account {username} has been created. You can now login to the blog and create content!‘)
# messages.success(request, f’Account created for {username}!’)
return redirect(‘login’)
# return redirect(‘blog-home’)
else:
form = UserRegisterForm()
return render(request, ‘users/register.html’, {‘form’: form})
and the urls.py file
from django.contrib import admin
from django.contrib.auth import views as auth_views
from django.urls import path, include
from users import views as user_views
urlpatterns = [
path(‘admin/’, admin.site.urls),
path(‘register/’, user_views.register, name=‘register’),
path(‘login/’, auth_views.LoginView.as_view(template_name=‘users/login.html’), name=‘login’),
path(‘logout/’, auth_views.LogoutView.as_view(template_name=‘users/logout.html’), name=‘logout’),
# path(‘login/’, auth_views.LoginView.as_view(template_name=‘users/login.html’), name=‘login’),
# path(‘logout/’, auth_views.LogoutView.as_view(), name=‘logout’),
path(‘’, include(‘zacsBlog.urls’)),
path(‘blog/’, include(‘zacsBlog.urls’)),
]