Hello, I add articles through the admin panel but not displayed on the site. Please help.

Here are my files

models.py

from django.db import models class Articles(models.Model): title = models.CharField(max_length = 120)#Максимальная длина строки 120 post = models.TextField() date = models.DateTimeField() image = models.ImageField(upload_to='products_images/') def __str__(self): return self.title 

urls.py in the folder where the models are located

 from django.urls import path, include from . import views from django.conf import settings from django.conf.urls.static import static from django.views.generic import ListView, DetailView from landing.models import Articles # Импорт база данных urlpatterns = [ # path('', views.index, name='index'), path('' , ListView.as_view(queryset=Articles.objects.all().order_by('-date')[:20], template_name='landing/home.html')), ] 

views.py in the folder where models are located

 from django.shortcuts import render from django.conf import settings from django.conf.urls.static import static from django.views.generic import ListView, DetailView from landing.models import Articles # Импорт база данных def index(request): return render(request, 'landing/home.html') 

Main url.py

 from django.contrib import admin from django.urls import path, include from django.conf import settings from django.contrib.staticfiles.urls import staticfiles_urlpatterns from django.conf.urls.static import static urlpatterns = [ path('admin/', admin.site.urls), path('', include('landing.urls')) ]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) 

I want to display the html file in this way

 from django.conf import settings from django.contrib import admin from landing.models import Articles {% extends "landing/header.html" %} {% load static %} {% block content %} {% load static %} <div class="col-lg-4"> <div class="tilt"> <h2 class="text-zagalovok">{{articles.title}}</h2> <h6 class="text-data">Опубликовано: {{articles.date|date:"Ymd в H:i:s"}}</h6> <div class="imgadmin"><img src="{{MEDIA_URL}}{{articles.image.url}}"></div> <p class="text-info">{{articles.post|safe|linebreaks}}</p> </div> </div> {% include "landing/footer.html" %} {% endblock %} 

But there is no result. I ask you to help it hard to understand this, especially since this version is already 2.0.1

  • What do python imports do in the template? - Sergey Gornostaev
  • But if you delete them will be displayed? - user279696
  • You have a wrong template - this is at least. It is necessary to sort the objects of the articles in a for loop - Mikhail Alekseevich
  • maybe this is related to views? I tried to add for but only the word "Published" is displayed - user279696

0