---
title: "LikeLion KKU postedit class"
date: 2019-10-10 00:00:00 -0400
categories: jekyll update
---
# 게시글을 수정해보자.
### templates폴더 안에 edit.html 생성 하기
```
```
### models.py 추가 및 수정
```
def edit(request, post_pk):
post = Post.objects.get(pk=post_pk)
if request.method == 'POST':
post.title = request.POST['title']
post.body = request.POST['body']
post.pub_date = timezone.datetime.now()
post.save()
return redirect('detail', post_pk)
else:
return render(request, 'edit.html')
```
### urls.py 추가
```
path('/edit', views.edit, name='edit'),
```
### detail.html 추가
```
post.pk %}">수정
```
---
title: "LikeLion KKU postedit class"
date: 2019-10-10 00:00:00 -0400
categories: jekyll update
---
# 게시글을 수정해보자.
### templates폴더 안에 edit.html 생성 하기
```
```
### models.py 추가 및 수정
```
def edit(request, post_pk):
post = Post.objects.get(pk=post_pk)
if request.method == 'POST':
post.title = request.POST['title']
post.body = request.POST['body']
post.pub_date = timezone.datetime.now()
post.save()
return redirect('detail', post_pk)
else:
return render(request, 'edit.html')
```
### urls.py 추가
```
path('/edit', views.edit, name='edit'),
```
### detail.html 추가
```
post.pk %}">수정
```
'코딩공부 > Python Django' 카테고리의 다른 글
KKU likelion django project (5) (0) | 2020.01.02 |
---|---|
KKU likelion django project (4) (0) | 2020.01.02 |
KKU likelion django project (2) (0) | 2020.01.02 |
KKU likelion django project (1) (0) | 2020.01.02 |
KKU likelion rest project (4) (0) | 2019.10.28 |