Answer the question
In order to leave comments, you need to log in
Why doesn't it display posts on the Django site?
Does not display posts on the main page of the site from the database, I don’t know what to do, I searched in the internet for options that don’t fit.
The problem is in the database, because if you just do a post, then everything is good, but if it’s in a cycle from the database, then it doesn’t display anything. Please tell me what to do?
PS There are no errors.
urls.py
from django.conf.urls import url, include
from . import views
from django.views.generic import ListView, DetailView
from main.models import AllFilms
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^$', ListView.as_view(queryset=AllFilms.objects.all().order_by("-date")[:12], template_name="main/homepage.html")),]
from django.shortcuts import render
from django.http import HttpResponse
from .models import AllFilms
def index(request):
posts = AllFilms.objects.all()
return render(request, 'main/homepage.html')
return render(request, 'blog/index.html', context = {'posts' : posts})
{% extends "main/wrapper.html" %}
{% block content %}
<h3>{{posts.title}}</h3>
{% for film in posts %}
<h3>{{film.title}}</h3>
{% endfor %}
{% endblock %}
from django.db import models
class AllFilms(models.Model):
title = models.CharField(max_length = 50)
img_src = models.TextField()
def __str__(self):
return self.title
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question