DB 읽고 화면에 출력하기
📌 index.html에 출력하기
① 데이터 가져오기.
(gal/views.py)
from django.shortcuts import render
from .models import Pic
# Create your views here.
def index(request):
p = Pic.objects.all()
context = {
"pset" : p
}
return render(request, "gal/index.html", context)
② 출력.
(index.html)
<h1>INDEX PAGE</h1>
{% for i in pset %}
<img src="{{ i.pic.url }}" height="150px">
{% endfor %}
<style>
img:hover {
opacity: 0.4;
}
</style>
DB 읽고 화면에 출력하기 - 결과
📌 DB 읽고 화면에 출력하기 - 결과
'Django' 카테고리의 다른 글
[Django] 사진 CRUD(5) - 사진 추가하기(C) (0) | 2022.12.20 |
---|---|
[Django] 사진 CRUD(4) - 사진 클릭 시, 삭제하기(D) (0) | 2022.12.20 |
[Django] 사진 CRUD(2) - 사진 관련 설정과 DB 생성 및 레코드 추가 (0) | 2022.12.20 |
[Django] 사진 관련 설정 (0) | 2022.12.20 |
[Django] 사진 CRUD(1) - 기본 세팅 (0) | 2022.12.20 |
댓글