HTML 파일로 Response 날리기
📌 Render( )
from django.shortcuts import render
# Create your views here.
def 함수 이름(request):
return render(request, 'app이름/생성한 html파일 이름.html')
Template 분리
📌 Template 분리
① template 폴더 안에 app마다 폴더 생성.
② app별로 해당 app에 대한 html 파일 생성해서 관리.
→ 사용하지 않는 app 관리에 용이함.
③ config/settings.py 수정.
...
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR/'templates'], # templates와 관련된 설정들은 여기에 있다고 명시해줌.
'APP_DIRS': True,
...
URL 분리
📌 URL 분리
: 해당 app에 관련된 url을 해당 app에서 관리하도록 url 분리를 함.
① app에 urls.py 파일 생성.
② config/urls.py 파일에 app의 urls 경로 추가.
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('app이름/', include('app이름.urls'))
]
③ app의 urls.py 파일에 경로 추가.
from django.urls import path
from . import views
urlpatterns = [
path('함수 이름/', views.함수 이름),
]
'Django' 카테고리의 다른 글
[Django] python shell로 데이터 CRUD (0) | 2022.12.12 |
---|---|
[Django] ORM과 DB 등록하기 (0) | 2022.12.12 |
[Django] path 및 앱 생성 명령어 (0) | 2022.12.06 |
[Django] Django 설치 및 프로젝트 시작 (0) | 2022.12.06 |
[Django] 가상 환경 설치 (0) | 2022.12.06 |
댓글