Python 该页不包含任何结果

Python 该页不包含任何结果,python,html,django,Python,Html,Django,当我试图导航到最后一页时,我遇到了这个错误,我该如何解决它?Nad Iam是一个自学成才的程序员,这真的阻止了我学习编码,请帮助我处理这个错误。 这是my home.html: {%extends "blog/base.html"%} {%block content%} {%for post in posts%} <article class="media content-section"> <img cla

当我试图导航到最后一页时,我遇到了这个错误,我该如何解决它?Nad Iam是一个自学成才的程序员,这真的阻止了我学习编码,请帮助我处理这个错误。 这是my home.html:

{%extends "blog/base.html"%} 
{%block content%}
    {%for post in posts%}
    <article class="media content-section">
      <img class = "rounded-circle aritcle-img" height = 80px width = 80px src="{{ post.author.profile.image.url }}" alt="">
        <div class="media-body">
          <div class="article-metadata">
            <a class="mr-2" href="{% url 'post-posts' post.author.username%}">{{ post.author }}</a>
            <small class="text-muted">{{ post.date_posted|date:"F d, Y" }}</small>
          </div>
          <h2><a class="article-title" href="{% url 'post-detail' post.id %}" >{{ post.title }}</a></h2>
          <p class="article-content">{{ post.content }}</p>
        </div>
      </article>
    {%endfor%}
    {% if is_paginated%}
    {% if page_obj.has_previous %}
      <a class = 'btn btn-outline-info mb-4' href="?page=1">First</a>
      <a class = 'btn btn-outline-info mb-4' href="?page={{ page_obj.previous_page_number}}">Previous</a>
    {% endif %}

    {% for num in page_obj.paginator.page_range %}
      {%if page_obj.number == num %}
      <a class = 'btn btn-info mb-4' href="?page={{ num }}">{{ num }}</a>
      {%elif num > page_obj.number|add:'-3' and num < page_obj.number|add:'3' %}
      <a class = 'btn btn-outline-info mb-4' href="?page={{ num }}">{{ num }}</a>

      {%endif%}
    {% endfor %}

    {% if page_obj.has_previous %}
      <a class = 'btn btn-outline-info mb-4' href="?page={{ page_obj.next_page_number }}">Next</a>
      <a class = 'btn btn-outline-info mb-4' href="?page={{ page_obj.paginator.num_pages }}">Last</a>
    {% endif %}
{% endif%}
{%endblock content%}
{%extends“blog/base.html”%}
{%block content%}
{posts%%中的post为%s}
{{发布日期{发布日期:“F d,Y”}

{{post.content}

{%endfor%} {%if已分页%} {%如果页面_obj.has_previous%} {%endif%} {page_obj.paginator.page_range%} {%if page_obj.number==num%} {%elif num>page_obj.number | add:'-3'和num
这是my views.py:

from django.shortcuts import render, get_object_or_404
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
from django.contrib.auth.models import User
from django.http import HttpResponse
from django.views.generic import ListView, DetailView, CreateView, UpdateView, DeleteView
from .models import Post
# Create your views here.
 
def home(request):
    context = {
        'posts' : Post.objects.all
    }
    return render(request,'blog/home.html',context)
class PostListView(ListView):
    model = Post
    template_name = 'blog/home.html'
    context_object_name = 'posts'
    ordering = ['-date_posted']
    paginate_by = 5
class UserPostListView(ListView):
    model = Post
    template_name = 'blog/user_posts.html'
    context_object_name = 'posts'
    ordering = ['-date_posted']
    paginate_by = 2

    def get_queryset(self):
        user = get_object_or_404(User, username= self.kwargs.get('username'))
        return Post.objects.filter(author=user).order_by('-date_posted')
    # <app>/<model><viewtype>.html
class PostDetailView(DetailView):
    model = Post
class PostCreateView(LoginRequiredMixin,CreateView):
    model = Post
    fields = ['title','content']    
    def form_valid(self, form):
        form.instance.author = self.request.user
        return super().form_valid(form)
class PostUpdateView(LoginRequiredMixin,UpdateView):
    model = Post
    fields = ['title','content']

    def form_valid(self, form):
        form.instance.author = self.request.user
        return super().form_valid(form)
 
    def test_func(self):
        post = self.get_object()
        if self.request.user == post.author:
            return True
        return False
class PostDeleteView(LoginRequiredMixin, UserPassesTestMixin,CreateView):
    #LoginRequiredMixin, UserPassesTestMixin,DeleteView
    #LoginRequiredMixin, AuthorMixin, ListView
    model = Post
    success_url = '/'
    def test_func(self):
        post = self.get_object()
        if self.request.user == post.author:
            return True
        else:
            return False
def about(request):
    return render(request,'blog/about.html',{'title':'About'})
从django.shortcuts导入渲染、获取对象或404
从django.contrib.auth.mixins导入登录名requiredMixin,UserPasseStMixin
从django.contrib.auth.models导入用户
从django.http导入HttpResponse
从django.views.generic导入ListView、DetailView、CreateView、UpdateView、DeleteView
从。模型导入后
#在这里创建您的视图。
def home(请求):
上下文={
“posts”:Post.objects.all
}
返回呈现(请求,'blog/home.html',上下文)
类PostListView(ListView):
型号=员额
模板名称='blog/home.html'
上下文\对象\名称='posts'
订购=['-发布日期']
分页单位=5
类UserPostListView(ListView):
型号=员额
模板名称='blog/user\u posts.html'
上下文\对象\名称='posts'
订购=['-发布日期']
分页单位=2
def get_queryset(自我):
user=get\u object\u或_404(user,username=self.kwargs.get('username'))
return Post.objects.filter(author=user).order_by('-date_posted'))
#/.html
类PostDetailView(DetailView):
型号=员额
类PostCreateView(LoginRequiredMixin,CreateView):
型号=员额
字段=['title','content']
def表单_有效(自身、表单):
form.instance.author=self.request.user
返回super().form_有效(form)
类PostUpdateView(LoginRequiredMixin,UpdateView):
型号=员额
字段=['title','content']
def表单_有效(自身、表单):
form.instance.author=self.request.user
返回super().form_有效(form)
def测试功能(自身):
post=self.get_对象()
如果self.request.user==post.author:
返回真值
返回错误
类PostDeleteView(LoginRequiredMixin、UserPasseStMixin、CreateView):
#LoginRequiredMixin、UserPasseStMixin、DeleteView
#LoginRequiredMixin、AuthorMixin、ListView
型号=员额
成功_url='/'
def测试功能(自身):
post=self.get_对象()
如果self.request.user==post.author:
返回真值
其他:
返回错误
def关于(请求):
返回呈现(请求,'blog/about.html',{'title':'about'})
请帮我找到下面代码中的错误,错误是在我点击最后一页时。所以问题是当我进入最后一页时,我发现了这个错误,请帮助我找到这个错误,这真的阻止了我学习编码