본문 바로가기
App Programming/Django

[Django] User Logout

by goatlab 2023. 3. 9.
728x90
반응형
SMALL

views.py

 

from django.contrib.auth import authenticate, login, logout

def logoutUser(request):
    logout(request)
    
    return redirect('home')

 

urls.py

 

from django.urls import path
from . import views

urlpatterns = [
    path('login/', views.loginPage, name = "login"),
    path('logout/', views.logoutUser, name = "logout"),
    
    path('', views.home, name = "home"),
    path('room/<str:pk>/', views.room, name = "room"),
    
    path('create-room/', views.createRoom, name = "create-room"),
    path('update-room/<str:pk>/', views.updateRoom, name = "update-room"),
    path('delete-room/<str:pk>/', views.deleteRoom, name = "delete-room")
]

 

navbar.html

 

<a href = "/">
    <h1>LOGO</h1>
</a>

<form method="GET" action="{% url 'home' %}">
    <input type="text" name="q" placeholder="Search Rooms..." />
</form>

{% if request.user.is_authenticated %}
<a href="{% url 'logout' %}">Logout</a>
{% else %}
<a href="{% url 'login' %}">Login</a>
{% endif %}

<hr>

728x90
반응형
LIST