Python 正确的链接在django中不起作用

Python 正确的链接在django中不起作用,python,django,Python,Django,好的,我正在创建一个应用程序,它显示一张带有标题和描述的图片。给你 {% block content %} <!-- MODAL IMAGE - This is the preview --> {% if projects %} {% for project in projects %} <div class="col-md-4 "> <div class="grid mask"> <figure>

好的,我正在创建一个应用程序,它显示一张带有标题和描述的图片。给你

{% block content %}

<!-- MODAL IMAGE - This is the preview -->
{% if projects %}

  {% for project in projects %}
  <div class="col-md-4 ">
      <div class="grid mask">
      <figure>
        <img class="img-responsive" src="{{ project.preview.url }}" alt="">
        <figcaption>
          <h5>{{ project.title }}</h5>
          <a data-toggle="modal" href="#modal1" class="btn btn-primary btn-lg">Take a Look</a>
        </figcaption><!-- /figcaption -->
      </figure><!-- /figure -->
      </div><!-- /grid-mask -->
  </div><!-- /col -->

     <!-- MODAL DETAIL - This is suppos to show the details -->
      <div class="modal fade" id="modal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
              <h4 class="modal-title">{{ project.title }}</h4>
            </div>
            <div class="modal-body">
              <p><img class="img-responsive" src="{{ project.preview.url }}" alt=""></p>
              <p>Category: {{ project.category }}</p>
              <p>Detail: {{ project.detail }}</p>
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
          </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
      </div><!-- /.modal -->
  {% endfor %}

{% endif %}
{% endblock %}
{%block content%}
{%if项目%}
{项目%中的项目为%}
{{project.title}
&时代;
{{project.title}

类别:{{project.Category}

详细信息:{{project.Detail}}

接近 {%endfor%} {%endif%} {%endblock%}
因此,该应用程序正在工作,当我添加一个新的项目图像时,它会显示创建的所有项目的预览。但是当我点击“看一看”时,它确实会显示弹出窗口,但是图像和标题总是指第一个图像和标题。简而言之,我的模态细节都是指第一个图像和标题

多谢各位。 例如,

您只能有一个具有给定ID的元素(
modal1
)。所有的“查看”链接都会打开第一个元素的
modal1
ID,因为其余元素的ID将被忽略。您需要为每个项目呈现唯一的ID,例如:

...
<a data-toggle="modal" href="#modal{{ project.pk }}" class="btn btn-primary btn-lg">Take a Look</a>
...
<div class="modal fade" id="modal{{ project.pk }}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
...
。。。
...
...

比我快。这可能还意味着您需要修改jquery函数,以针对这些新的模态。这看起来像是引导代码,它应该从
节点的
href
属性中获取模态元素的ID,因此可能不需要更改JS。是的,这是引导,我正试图让它与django一起工作:)@lanzz谢谢你,你是对的,我没有意识到,我假设它会引用列表中的当前项目,因为它在同一个for循环中。它现在起作用了,非常感谢