최신글
hyeonga_code
파이선 웹구축_장고_21_계정 비밀번호 변경 본문
반응형
- 계정 비밀번호 변경
1. 업데이트 페이지에 버튼 생성 <templates> > <adm> > 'update.html'
'update.html'
=====
1
2
3
4
5
6
|
<h1><b>UPDATE PAGE</b></h1>
<br><br>
<form method="post">
<a href="{% url 'chpass' %}"><button type="button">Change Password</button></a>
</form>
|
cs |
2. 경로 설정 <adm> > 'urls.py'
'urls.py'
=====
1
2
3
4
5
6
|
from django.urls import path, include
from . import views
urlpatterns = [
path('chpass/', views.chpass, name="chpass")
]
|
cs |
3. 함수 설정 <adm> > 'views.py'
'views.py'
=====
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
from django.shortcuts import render, redirect
from django.contrib.auth import authenticate, login, logout
from .models import User
from django.contrib.auth.hashers import check_password
def chpass(request):
if request.user.is_anonymous:
return redirect("login")
if request.method == "POST":
u = request.user
cp = request.POST.get("cpass")
if check_password(cp, u.password):
np = request.POST.get("npass")
u.set_password(np)
u.save()
return redirect("login")
return render(request, "adm/chpass.html")
|
cs |
4. 비밀번호 변경 페이지 작성 <templates> > <adm> > 'chpass.html'
'chpass.html'
=====
1
2
3
4
5
6
7
8
9
|
<h1><b>PASSWORD CHANGE</b></h1>
<form method="post">
{% csrf_token %}
<input type="password" name="cpass" placeholder="INPUT CURRENT PASSWORD" size="50"><br><br>
<input type="password" name="npass" placeholder="INPUT NEW PASSWORD" size="50"><br><br>
<button>Change</button>
<a href="{% url 'update' %}"><button type="button">Cancle</button></a>
</form>
|
cs |
반응형
'Python_Django' 카테고리의 다른 글
파이선 웹구축_장고_23_댓글 등록 (0) | 2023.06.15 |
---|---|
파이선 웹구축_장고_22_댓글_상속 테이블 (0) | 2023.06.14 |
파이선 웹구축_장고_20_계정 프로필 수정 (0) | 2023.06.12 |
파이선 웹구축_장고_19_계정 회원가입 페이지 (0) | 2023.06.11 |
파이썬 웹구축_장고_18_계정 삭제 (0) | 2023.06.10 |