Django:使用ManyToManyField迭代两个for循环

2024-05-15 11:08:41 发布

您现在位置:Python中文网/ 问答频道 /正文

大家好,我在这一个挣扎,谷歌搜索这一个核心。在

我正在开发一个图像库,每个相册都有输出,当单击屏幕覆盖显示图像库。为了在图库中显示每个图像,我们在javascript中做了大量的工作,因此我只需要图像路径,该路径由:

{{ images.content }}

以下是我在django项目中使用的文件。在

这方面的帮助太棒了。在

在管理.py在

^{pr2}$

在视图.py在

from django.http import HttpResponse
from notices.models import Notices
from django.shortcuts import get_object_or_404
from django.shortcuts import render_to_response
from gallery.models import *
from navigation.models import *

# when the galleries page is requested, all image galleries are listed by date created with the latest first,
# each gallery displayed contains a javascript tag containing an index of images separated by ';'
def galleries(request):
    gallery = Gallerys.objects.all()
    images = Images.objects.all()

    return render_to_response('galleries.html', {'Galleries': gallery, 'Images': images})

在图库.html在

        {% for galleries in Galleries %}
            <h1>{{ galleries.title }}</h1>
            {% for images in galleries.gallery.all %}
                <h2>{{ images.content }}</h2>
            {% empty %}
                none
            {% endfor %}
        {% endfor %}

当我迭代:

<h2>{{ images.content }}</h2>

我什么都没得到,我哪里出错了?在

谢谢!在


Tags: djangofrompy图像import路径modelsh2