Django
[Django] 사진 CRUD(3) - DB 읽고 화면에 출력하기(R)
기록하는_사람
2022. 12. 20. 20:55
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 읽고 화면에 출력하기 - 결과