accounts μ± μμ±(startapp)
settings.INSTALLED_APPSμ μΆκ°
accounts/urls.py μμ±
νλ‘μ νΈ/urls.pyμ include
accounts/views.py
from django.contrib.auth.decorators import login_required
from django.contrib.auth.views import LoginView, LogoutView
from django.shortcuts import render
from django.views.generic import CreateView
login = LoginView.as_view(
template_name="accounts/login_form.html",
)
logout = LogoutView.as_view(
next_page="/accounts/login/",
)
@login_required
def profile(request):
return render(request, "accounts/profile.html")
signup = CreateView.as_view()
accounts/urls.py
from django.urls import path
from accounts import views
urlpatterns = [
path("login/", views.login),
path("logout/", views.logout),
path("profile/", views.profile),
path("signup/", views.signup),
]
login_form.html
<h2>login</h2>
<form action="" method="post">
{% csrf_token %}
<table>
{{ form.as_table }}
</table>
<input type="submit" value="Login" />
</form>
profile.html
<h2>{{ user }}'s Profile</h2>
signup_form.html (login_form.htmlκ³Ό κ±°μλμΌ)
<h2>Signup</h2>
<form action="" method="post">
{% csrf_token %}
<table>
{{ form.as_table }}
</table>
<input type="submit" value="signup" />
</form>