반응형
Using the Django authentication system | Django documentation | Django
Using the Django authentication system ¶ This document explains the usage of Django’s authentication system in its default configuration. This configuration has evolved to serve the most common project needs, handling a reasonably wide range of tasks, and has a careful implementation of passwords an...
docs.djangoproject.com
1. Login Page를 만든다.
<div class="input-group">
<span class="input-group-text w-25">ID</span>
<input type="text" class="form-control" name="login-id" aria-describedby="idHelp" placeholder="ID">
</div>
<div class="input-group">
<span class="input-group-text w-25">Password</span>
<input type="password" class="form-control" name="login-password" placeholder="Password">
</div>
<button type="submit" class="btn btn-primary">Login</button>
2. Login Url을 등록한다.
path('dologin', views.dologin, name='dologin'),
3. Login View를 만든다.
def dologin(request):
loginid = request.POST['login-id']
loginpassword = request.POST['login-password']
user = authenticate(request, username=loginid, password=loginpassword)
if user is not None:
login(request, user)
return index(request)
4. Auth에 따른 페이지의 분기는 is_authenticated를 사용한다.
{% if request.user.is_authenticated %}
<li class="nav-item"><a class="nav-link px-lg-3 py-3 py-lg-4" href="/admin">Admin</a></li>
{% endif %}
Django는 이미 Auth 관련 기능을 기본 제공하므로 우리는 그냥 잘 사용하면 된다.
반응형
'Django' 카테고리의 다른 글
Django에서의 request의 multipart 파일 처리 (0) | 2022.02.08 |
---|---|
Django Login, Logout 템플릿 이용하기 (0) | 2022.02.08 |
Visual Studio Code에서 Django Debug Mode (0) | 2022.02.08 |
django db admin 계정 사용하기. create user (0) | 2022.02.08 |
Python Shell 이용하여 명령어 실행시키기 (0) | 2022.02.08 |