From c40e27a3f9bd1d5e5ad84c78df5d87ee9d78ba4b Mon Sep 17 00:00:00 2001 From: Bobson Lin Date: Mon, 8 Jul 2019 11:05:41 +0800 Subject: [PATCH] feat: Forum App - 5. Add Logout Endpoint --- community/community/settings.py | 1 + community/forum/templates/navbar.html | 30 ++++++++++++------- .../templates/user_profile/login.html | 4 +-- community/user_profile/urls.py | 1 + community/user_profile/views.py | 2 ++ 5 files changed, 26 insertions(+), 12 deletions(-) diff --git a/community/community/settings.py b/community/community/settings.py index 696782c..aaa9610 100644 --- a/community/community/settings.py +++ b/community/community/settings.py @@ -124,3 +124,4 @@ STATIC_URL = '/static/' LOGIN_URL = '/login/' LOGIN_REDIRECT_URL = '/' +LOGOUT_REDIRECT_URL = '/' diff --git a/community/forum/templates/navbar.html b/community/forum/templates/navbar.html index 28321dc..dca3af5 100644 --- a/community/forum/templates/navbar.html +++ b/community/forum/templates/navbar.html @@ -23,7 +23,7 @@
@@ -27,9 +26,10 @@
{{ form.password }}
- {{ form.username.errors }}
+ {{ form.non_field_errors }} +
diff --git a/community/user_profile/urls.py b/community/user_profile/urls.py index fdca392..e16783d 100644 --- a/community/user_profile/urls.py +++ b/community/user_profile/urls.py @@ -9,5 +9,6 @@ urlpatterns = [ auth_view.LoginView.as_view(template_name='user_profile/login.html', authentication_form=ExtendedAuthenticationForm), name='login'), + path('logout', auth_view.LogoutView.as_view(), name='logout'), path('profile', views.profile, name='profile') ] diff --git a/community/user_profile/views.py b/community/user_profile/views.py index eb634ae..26c0bb7 100644 --- a/community/user_profile/views.py +++ b/community/user_profile/views.py @@ -1,5 +1,6 @@ from django.shortcuts import render, redirect from django.contrib.auth import authenticate, login +from django.contrib.auth.decorators import login_required from .forms import ExtendedUserCreationForm @@ -19,5 +20,6 @@ def register(request): return render(request, 'user_profile/register.html', {'form': form}) +@login_required def profile(request): return render(request, 'user_profile/profile.html')