MVC
Model
▶ django와 Database를 연결
▶ Row(Item)과 Columns(Attributes)
▷ django의 Article = Database의 Row
▷ django의 Title, image 등 = Database의 Columns
View
▶ djange의 계산의 대부분
▶ Server의 응답
▷ 유저가 로그인 되어 있는지
▷ 요청이 유효한지
▷ DB에서 가져오기
▷ 유저에게 돌려주기
Template
▶ FrontEnd와 유사
▷ Server에서 전달할 때 게시글 구현해주는 작업
▷ 정적인 언어 → 동적인 언어
📝 하나의 아티클 반환
<title>Title</title>
↓
<title>{{Article.title}}</title> #입력받은 아티클로 나타내고 싶을 때
📝 여러개의 아티클 반환
<body>
{% for article in article_list %}
<p>{{article.title}}</p>
{% endfor %}
</body>
Template : 유저인터페이스 / View : 계산(인증, 확인 등) / Model : 데이터 저장되는 곳과 쉽게 연결
python manage.py startapp accountapp
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'accountapp',
]
from django.http import HttpResponse
from django.shortcuts import render
# Create your views here.
def hello_world(request):
return HttpResponse('Hello world!')
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('account/', include('accountapp.urls')),
]
from django.urls import path
from accountapp.views import hello_world
app_name = 'accountapp'
urlpatterns = [
path('hello_world/', hello_world, name='hello_world')
]