Building a Django Web App – Django I > Django functionality II

Django I에서 다루게 될 내용은 다음과 같습니다.

2-1 Django installation and configuration

2-2 Django overview and debugging

2-3 Django + Bootstrap

2-4 Django functionality I

2-5 Django functionality II


이번에는 Django functionality II 입니다.

2-5 Django functionality II

(1) Connecting HTML files with DTL

header.html 생성

다음과 같이 header.html 파일을 생성합니다.

mysite > main > templates > main > (New File) header.html

 

header.html 추가

다음과 같이 코드를 추가합니다.

 

block content 로드

다음과 같이 코드를 추가합니다.

mysite > main > templates > main > header.html

 

home.html 수정

다음과 같이 코드를 수정합니다.

mysite > main > templates > main > home.html

 

브라우저에서 확인해 봅니다.

 

(2) Creating a separate navbar template

navbar.html 생성

다음과 같이 navbar.html 파일을 생성합니다.

mysite > main > templates > main > (New Folder) includes > (New File) navbar.html

navbar.html 추가

다음과 같이 코드를 추가합니다.

 

navbar.html를 header.html로 연결

다음과 같이 코드를 수정합니다.

mysite > main > templates > main > header.html

 

products.html 생성

다음과 같이 products.html 파일을 생성합니다.

mysite > main > templates > main > (New File) products.html

 

products.html 추가

다음과 같이 코드를 추가합니다.

 

urls.py에 products 경로 추가

다음과 같이 코드를 추가합니다.

mysite > main > urls.py

 

views.py에 product function 추가

다음 코드를 추가합니다.

mysite > main > views.py

 

products.html 업데이트

다음과 같이 코드를 추가합니다.

mysite > main > templates > main > products.html

 

product link를 navbar.html로 추가

다음과 같이 코드를 추가합니다.

mysite > main > templates > main > includes > navbar.html

 

브라우저에서 확인해 봅니다.

 

(4) Using Django pagination

product link를 navbar.html로 추가

다음과 같이 코드를 추가합니다.

mysite > main > views.py

 

Pagination을 products.html에 추가

다음과 같이 코드를 추가합니다.

mysite > main > templates > main > products.html

 

브라우저에서 확인해 봅니다.

Leave a Reply

Your email address will not be published. Required fields are marked *

인기 글

Ubuntu 22.04 LTS에 Python 3.8 or 3.9 설치 방법
서버 : Vultr 클라우드OS: Ubuntu 22.04 LTS사용자 계정 생성하여 설치 진행함1. Start with the system updatesudo apt update...
오라클 클라우드 OCI 가입 드디어 성공 했습니다 (상세 후기)
2023년 2월 16일에 ‘오라클 클라우드 지급 검증 실패 글‘을 남긴 적이 있습니다.그 때 검색을 통해 해결 방법을 찾아 보았고, 당시 성공했던 분들의...
Ubuntu 20.04에 MySQL 5.7 설치
비씨티원 인공지능 서비스 플랫폼 BAP(Bctone AI service Platform)의 설치 환경은 공식적으로 Ubuntu 18.04와 MySQL 버전 5.7 입니다. 최근 Ubuntu...
WSL2/Ubuntu 22.04 LTS에 Anaconda 설치 
WSL2/Ubuntu 환경에서 Python 버전별로 가상환경을 만드는 방법 중 그나마 Anaconda 방법이 좋은 것 같네요. 설치 방법은 간단합니다.1. apt update사용자...
워드프레스 글 또는 페이지 클릭 시 특정 URL로 이동하는 방법
워드프레스의 글 또는 페이지 클릭 시 특정 사이트로 이동하고 싶을 때가 있습니다. 이 때 활용하기 좋은 워드프레스 플러그인으로서 다음과 같은 Page Links To 가 있습니다.      Page...