ユーザーのログインとログアウト

3073 ワード

ログイン.HTML
<form method="POST">
    {% csrf_token %}
    {{ form }}
    <button type="submit" class="btn btn-outline-info">LOGIN</button>
        <a href="{% url 'register' %}">SIGN UP</a>
    </form>

URL.Py (メインプロジェクト)
from django.contrib import admin
from django.urls import path
from django.contrib.auth import views as user_views

urlpatterns = [
    path('admin/', admin.site.urls),
path('login/',user_views.LoginView.as_view(template_name='app/login.html'),name='login'),
    path('logout/',user_views.LogoutView.as_view(),name='logout'),
]


設定パイ
LOGIN_REDIRECT_URL = 'home' ('Put your URL you want to redirect')
LOGOUT_REDIRECT_URL = 'login' ('Put your URL you want to redirect')
エンジョイ!