博客类别中的Python Django for循环错误

问题描述 投票:0回答:1

views.py

class PostDetail(DetailView):
template_name = "posts/single.html"
model = Post
context_object_name = "single"
def get_context_data(self, **kwargs):
    context = super(PostDetail, self).get_context_data(**kwargs)
    context['allCategories'] = Category.objects.all()

    return context

models.py

class PostDetail(DetailView):
template_name = "posts/single.html"
model = Post
context_object_name = "single"
def get_context_data(self, **kwargs):
    context = super(PostDetail, self).get_context_data(**kwargs)
    context['allCategories'] = Category.objects.all()

    return context

single.html

   <ul>
                           {% for category in allCategories %}
                            <li>
                                <a href="#">{{ category.title }} <span>{{ category.postCount }}</span></a>
                            </li>
                            {% endfor %}
                        </ul>
                    </div>

我在博客中看不到类别。而且我没有任何警告。

python django for-loop web blogs
1个回答
0
投票

enter image description here

enter image description here

这些照片属于Django管理面板和我的网站屏幕快照。

© www.soinside.com 2019 - 2024. All rights reserved.