model.py -> 데이터베이스 X
데이터 = 객체
id column (PK) 장고에서 기본적으로 제공
클라이언트(웹) -> 서버: request
서버 -> 클라이언트(웹): response
view.py -> 데이터베이스에서 객체를 가져옴
- urls.py -> 그 객체를 어떤 주소로 보여줄지
- templates -> 그 객체를 어떤 리소스랑 결합할지
form 태그: 사용자의 입력을 전달받기 위해서 사용
path converter (urls.py)
.
.
.
path('blog/<int:blog_id>',views.detail,name='detail'),
]
views.py에서 redirect랑 render 차이:
- render 사용 시 새로고침하면 요청 날라감
- redirect는 GET요청을 계속 날아가게 해줌
forms.py -> 유효성 검사 ex) 제목/내용 없이 게시물 업로드 상황 방지
from django import forms
from .models import Blog
class BlogForm(forms.ModelForm):
class Meta:
model = Blog
fields = ['title', 'content']
그리고, views.py에서
from .forms import BlogFrom 추가
<순서>
urls -> views -> templates (html)