로그아웃은 보안상의 이슈로 POST요청으로 구현
# urls.py
from django.contrib.auth.views import LoginView, LogoutView
from django.urls import path
from .views import SignupView
app_name = 'accounts'
urlpatterns = [
path('signup/', SignupView.as_view(), name='signup'),
path('login/', LoginView.as_view(template_name='accounts/login.html'), name='login'),
path('logout/', LogoutView.as_view(), name='logout'),
]
<!-- index.html -->
{% if not user.is_authenticated %}
<a href="{% url 'accounts:signup' %}">회원가입</a>
<a href="{% url 'accounts:login' %}?next={{ request.path }}">로그인</a>
{% else %}
{{user}}
<form method="post" action="{% url 'accounts:logout' %}?next={{ request.path }}">
{% csrf_token %}
<input type="submit" value="로그아웃">
</form>
{% endif %}
<!-- accounts/login.html -->
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ form }}
<input type="submit" value="로그인">
</form>
우선순위1. html파일에 next인자
우선순위2. settings.py에 REDIRECT_URL
LOGIN_REDIRECT_URL
LOGOUT_REDIRECT_URL
우선순위3 Default