from django.shortcuts import render
from django.views.generic import ListView
from .models import Product
# Create your views here.
class ProductList(ListView):
model = Product
from django.contrib import admin
from django.urls import path
from fcuser.views import index, RegisterView, LoginiView
from product.views import ProductList
urlpatterns = [
path('admin/', admin.site.urls),
path('', index),
# class는 .as_view()를 입력!
path('register/', RegisterView.as_view()),
path('login/', LoginiView.as_view()),
path('product/', ProductList.as_view()),
]
{% extends "base.html" %}
{% block contents %}
Product
{% endblock %}
from django.shortcuts import render
from django.views.generic import ListView
from .models import Product
# Create your views here.
class ProductList(ListView):
model = Product
template_name = 'product.html'
{% extends "base.html" %}
{% block contents %}
{% for product in object_list %}
{{product.name}} : {{product.price}}
{% endfor %}
{% endblock %}
from django.shortcuts import render
from django.views.generic import ListView
from .models import Product
# Create your views here.
class ProductList(ListView):
model = Product
template_name = 'product.html'
# object_list로 사용하기 싫으면 context_object_name으로 변경 가능
context_object_name = 'product_list'
{% extends "base.html" %}
{% block contents %}
{% for product in product_list %}
{{product.name}} : {{product.price}}
{% endfor %}
{% endblock %}
{% extends "base.html" %}
{% block contents %}
<div class="row mt-5">
<div class="col-12">
<table class="table table-light">
<thead class="thead-light">
<tr>
<th scope="col">#</th>
<th scope="col">상품명</th>
<th scope="col">기격</th>
<th scope="col">등록날짜</th>
</tr>
</thead>
<tbody class="text-dark">
{% for product in product_list %}
<tr>
<th scope="row">{{product.id}}</th>
<th>{{product.name}}</th>
<th>{{product.price}}</th>
<th>{{product.register_date}}</th>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endblock %}
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
'fcuser',
'product',
'order',
]
{% extends "base.html" %}
<!-- 필터를 사용할 수 있게 해준다 -->
{% load humanize%}
{% block contents %}
<div class="row mt-5">
<div class="col-12">
<table class="table table-light">
<thead class="thead-light">
<tr>
<th scope="col">#</th>
<th scope="col">상품명</th>
<th scope="col">가격</th>
<th scope="col">등록날짜</th>
</tr>
</thead>
<tbody class="text-dark">
{% for product in product_list %}
<tr>
<th scope="row">{{product.id}}</th>
<th>{{product.name}}</th>
<th>{{product.price|intcomma}}원</th>
<th>{{product.register_date|date:'Y-m-d H:i'}}</th>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endblock %}
date : https://docs.djangoproject.com/en/3.1/ref/templates/builtins/