[멋쟁이사자처럼 11기] 6회차: Django U, D

젠니·2023년 12월 3일

Likelion-11th

목록 보기
6/8

model은 데이터베이스인가?

model.py는 데이터베이스가 아니다!

  • 데이터 = 객체
  • id column (PK) 장고에서 기본적으로 제공

request와 response 차이

  • 클라이언트(웹) -> 서버: request
  • 서버 -> 클라이언트(웹): response

redirect와 render 차이

  • render 사용 시 새로고침하면 요청 날라감
  • redirect는 GET요청을 계속 날아가게 해줌

views.py -> 데이터베이스에서 객체를 가져옴

  • urls.py -> 그 객체를 어떤 주소로 보여줄지
    - path converter (urls.py)
.
.
.
path('blog/<int:blog_id>',views.detail,name='detail'),
]
  • templates -> 그 객체를 어떤 리소스랑 결합할지

form 태그

  • 사용자의 입력을 전달받기 위해서 사용

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)

*멋사 포스팅은 티스토리에 업로드 된 글의 백업입니다.
출처: Jenvelop log

profile
젠니의 개발 라이푸우

0개의 댓글