hyeonga_code

파이선 웹구축_장고_20_계정 프로필 수정 본문

Python_Django

파이선 웹구축_장고_20_계정 프로필 수정

hyeonga 2023. 6. 12. 05:59
반응형

- 계정 프로필 수정

1. 프로필 페이지에 수정 버튼 생성 <templates> > <adm> > 'profile.html'

'profile.html'

=====

1
2
3
4
5
<h1><b>PROFILE PAGE</b></h1>
<br><br>
 
<a href="{% url 'update' %}"><button type='button'>Update</button></a>
 
cs

 

 

 

 

 

2. 경로 설정 <adm> > 'urls.py'

'urls.py'

=====

1
2
3
4
5
6
from django.urls import path, include
from . import views
 
urlpatterns = [
    path('update/', views.update, name='update'),
]
cs

 

 

3. 함수 생성 <adm> > 'views.py'

'views.py'

=====

1
2
3
4
5
6
from django.shortcuts import render, redirect
from django.contrib.auth import authenticate, login, logout
from .models import User
 
def update(request):
    return render(request, "adm/update.html")
cs

 

 

 

 

4. 업데이트 페이지 작성 <templates> > <adm> > 'update.html'

'update.html'

=====

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<h1><b>UPDATE PAGE</b></h1>
<br><br>
 
<form method="post">
    {% csrf_token %}
    <input type='text' disabled value="{{user}}"><br><br>
    #_ 아이디 변경 불가
    <input type='text' name='umail' value="{{user.email}}"><br><br>
    <input type='text' name='fname' value="{{user.first_name}}"><br><br>
    <input type='text' name='lname' value="{{user.last_name}}"><br><br>
 
    <button>Update</button>
    <a href="{% url 'profile' %}"><button type='button'>Cancle</button></a>
</form>
cs

 

 

반응형