为什么帖子没有显示在主页上?

问题描述

当我在管理面板中添加帖子时,这些帖子未显示在应用程序的主页上。 它只显示帖子的空格,而不能在首页上显示帖子的文章。

views.py

from django.shortcuts import render,HttpResponseRedirect
from django.contrib import messages
from django.http import HttpResponse
from .forms import SignUpForm,LoginForm
from django.contrib.auth import authenticate,login,logout
from .models import Post
# Create your views here.

# home
def home(request):
    posts = Post.objects.all()
    return render(request,'blog/home.html',{'posts':posts})

home.html

{% extends 'blog/base.html' %}
{% load static %}

{% block content %}

<div class="col-sm-10">
  <h3 class="text-white my-5">Home Page</h3>
    {% for post in posts %}
      <div class="jumbotron jumbotron-fluid jumbo-colour">
        <div class="container">
          <h1 class="display-4 font-weight-bold">{{posts.title}}</h1>
          <p class="lead">{{posts.desc}}</p>
        </div>
      </div>
    {% endfor %}
</div>

{% endblock content %}

models.py

from django.db import models

# Create your models here.
class Post(models.Model):
    title = models.CharField(max_length=150)
    desc = models.TextField()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)