首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Bootstrap model,django for loop and model

Bootstrap model,django for loop and model
EN

Stack Overflow用户
提问于 2014-09-25 14:58:08
回答 1查看 2.4K关注 0票数 3

我对Django和Bootstrap都是新手。我目前正在尝试在我的Django模板中的for循环中创建一个bootstrap模式窗口,它将显示来自模型的一些数据。

因此,我创建了一个for循环,它涵盖了按钮创建和模式窗口,并迭代了我的模型中包含的数据。因此,它应该创建与我的模型中的条目一样多的按钮和相应的模式窗口。

但是,当我单击通过for循环创建的任何按钮时,模式窗口始终显示第一个条目,并且从不更改。

我一直在努力寻找答案,主要看了以下几个主题:

Passing value to Bootstrap modal in Django

Twitter bootstrap remote modal shows same content everytime

当我创建与唯一ID相关的不同模式和按钮时,这在循环之外工作得很好,但我不能在我的例子中工作。

我希望是足够精确的。

谢谢你的帮助。

代码语言:javascript
复制
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Remote file for Bootstrap Modal</title>  

  <!--CSS-->
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">

  <!--jquery-->
  <script src="http://code.jquery.com/jquery.min.js"></script>

  <!--JS-->
  <script src="http://getbootstrap.com/dist/js/bootstrap.js"></script>


</head>
<body>

          <div class="row">
            {% for name in activities %}
          <div class="col-md-3">
            <div class="thumbnail">
              <img src="#" >
            </div>
            <p>Location: {{name.aregion}}</p>
            <p>

              <!-- Button trigger modal -->
              <button class="btn btn-primary btn-xs" data-toggle="modal" data-target="#myModal">
                Read More
              </button>

              <!-- Modal -->
              <div class="modal fade" id="myModal" 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"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                      <h4 class="modal-title" id="myModalLabel">{{name.aname}}, {{name.aregion}}, {{name.acountry}}</h4>
                    </div>
                    <div class="modal-body">
                      ...
                    </div>
                    <div class="modal-footer">
                      <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                      <button type="button" class="btn btn-primary">Save</button>
                    </div>
                  </div>
                </div>
              </div>
            </p>
          </div>
          {% endfor %}
          </div>

</body>
</html>

(“按钮触发模式”和“模式”代码来自bootstrap.com,所以它应该是正确的)

EN

回答 1

Stack Overflow用户

发布于 2014-09-26 02:01:43

好了,我已经知道哪里出问题了。我试图使用的ID是文本,而不是我认为的数字,最终是如此简单。我最终使用了我的模型的id字段,它工作得很好。感谢你,rajasimon,给我们指明了正确的方向!

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26032486

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档