S
S
SHADRIN2020-04-27 20:15:57
Django
SHADRIN, 2020-04-27 20:15:57

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")),]

views.py

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})


homepage.py
{% extends "main/wrapper.html" %}

{% block content %}
  <h3>{{posts.title}}</h3>
  {% for film in posts %}
    <h3>{{film.title}}</h3>
  {% endfor %}

{% endblock %}


models.py

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

1 answer(s)
D
DUDE, 2020-04-28
@shadrin_ss

Your return with the context in which the posts are located does not work, because there is another return before it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question