Хочу создать вывод даты но выдает ошибку . Миграцию сделал. Python , django
products.html
{% extends "ShapeHtml/wrapper.html" %} {% block content %} {% for product in products_list %} <div id="next-block"> <div class="row centered"> <div class="panel panel-default"> <div class="panel-heading"> <p><img src="{{ MEDIA_URL }}{{ product.img.url }}"/></p> </div> <div class="panel-body"> <a href="/shop/{{product.id}}"> <h1> {{product.title}} </h1> </a> <h3 align="right">{{products.date|date:"d-m-Y"}}</h3> </div> </div> </div> </div> </div> {% endfor %} {% endblock %}
models.py
from django.db import models # Create your models here. from django.db import models from django import forms # Create your models here. class Products(models.Model): title = models.CharField(max_length=200) post = models.TextField() date = models.DateTimeField() img = models.ImageField(upload_to='') def __str__(self): return self.title
urls.py
from django.urls import path, include from django.views.generic import ListView, DetailView from django.conf.urls.static import static from django.conf import settings from . models import Products urlpatterns=[ path('', ListView.as_view(queryset=Products.objects.all().order_by("-date")[:20],template_name="shop/products.html")), path('<int:pk>/', DetailView.as_view(model=Products, template_name="shop/product.html")) ]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
vies.py
from django.shortcuts import render # Create your views here. from django.views import generic from .models import Products class IndexView(generic.ListView): template_name = "shop/products.html" context_object_name = 'products_list' def get_queryset(self ): return Products.objects.all()