Django,我的 for 循环没有显示在包含模板中

Django, my for loop is not showing in include template

您好,我是 Django 和 Python 的初学者。我目前在我的项目中使用模板中的 for 循环,但它没有显示任何内容。有人可以帮助我并解释我做错了什么吗?

models.py

class ImageCategory(models.Model):
    name = models.CharField(blank=False, max_length=120)
    created_at = models.DateTimeField(default=datetime.now(), blank=True)

    class Meta:
        verbose_name_plural = "image categories"

    def __str__(self):
        return self.name

views.py

from .models import ImageCategory

def HomeView(request):
template = loader.get_template('editor.html')

return HttpResponse(template.render())


def LibraryOverviewView(request):  
    return render(request, 'library_overview.html', {'image_categories': ImageCategory.objects.all()})

所以我把类目信息放在libraryOverView里,但是editor.html用的是HomeView。 library_overview.html 包含在另一个名为 editor.html

的 html 中

editor.html

section class="toolbox document-tools">
              <ul>
                <li class="tb-title">Document</li>
                <!-- uncomment to see all available styles -->
                <!--
                <li class="tb-btn tb-btn-big tb-btn-disabled">Preview</li>
                -->
                <li class="tb-btn tb-btn-big" id="btn-export">Export</li>
                <li class="tb-btn tb-btn-big tb-btn-action">Save</li>
              </ul>
            </section>

          </span>

          {% include 'library_overview.html' %}

          {% include 'library_categories/colorful_images.html' %}

          {% include 'library_categories/colorful_images_categories/blue_images.html' %}

        </span>

library_overview.html

{% for category in image_categories %}
     <a class="tb-btn tb-btn-label tb-btn-radio no-bg slide-forward">-> {{ category.name }}</a>
 {% empty %}
     <p> There are no Categories yet </p>
 {% endfor %}

urls.py

urlpatterns = [url(r'^library_overview/', views.LibraryOverviewView, 
    name='LibraryOverviewView'),

editor.html 使用的是 HomeView,而不是 LibraryOverviewView。但是 libraryOverviewView 的 html 包含在 editor.html 中,因此仍然使用 HomeView。将信息从 LibraryOverView 移动到 HomeView 成功了。