Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用Django将内容从数据库动态加载到引导模式_Python_Django_Twitter Bootstrap_Modal Dialog_Bootstrap Modal - Fatal编程技术网

Python 如何使用Django将内容从数据库动态加载到引导模式

Python 如何使用Django将内容从数据库动态加载到引导模式,python,django,twitter-bootstrap,modal-dialog,bootstrap-modal,Python,Django,Twitter Bootstrap,Modal Dialog,Bootstrap Modal,我正在开发一个测试应用程序,它在HTML表格中列出数据库中的用户,我想要实现的是,当您单击某个特定记录或行的任何图标时,该记录的完整细节将显示在引导模式中。我的问题是如何实现视图、URL和模板?我需要Javascript帮助吗?因为在PHP中,这在没有JavaScript的情况下很容易实现。请允许我选择代码示例作为对我的问题的更正,谢谢 以下是我的观点 def users(request): get_users = User.objects.all() return render

我正在开发一个测试应用程序,它在HTML表格中列出数据库中的用户,我想要实现的是,当您单击某个特定记录或行的任何图标时,该记录的完整细节将显示在引导模式中。我的问题是如何实现视图、URL和模板?我需要Javascript帮助吗?因为在PHP中,这在没有JavaScript的情况下很容易实现。请允许我选择代码示例作为对我的问题的更正,谢谢

以下是我的观点

def users(request):
    get_users = User.objects.all()
    return render(request, 'classwork_app/users.html', {'users':get_users})
我的URL

from classwork_app import views

app_name = 'classwork_app'

urlpatterns = [
    path('', views.users, name='users'),
]
<table class="table table-bordered">
            <tr>
              <th>S/N</th>
              <th>Username</th>
              <th>Firstname</th>
              <th>Lastname</th>
              <th colspan="2">Action</th>
            </tr>

            {% if users %}
              {% for u in users %}
                <tr>
                  <td>{{ forloop.counter }}</td>
                  <td>{{ u.username }}</td>
                  <td>{{ u.first_name }}</td>
                  <td>{{ u.last_name }}</td>
                  <td style="font-size: 12px"><a data-toggle="modal"  href="#MyModal{{ u.id }}"><i class="fa fa-eye"></i></a></td>
                </tr>
              {% endfor %}
            {% endif %}

          </table>

          <div id="#MyModal{{ u.id }}" class="modal fade" role="dialog">
            <div class="modal-dialog">

              <!-- Modal content-->
              <div class="modal-content">
                <div class="modal-header">
                  <button type="button" class="close" data-dismiss="modal">&times;</button>
                  <h4 class="modal-title">{{ u.first_name }} {{ u.last_name }}</h4>
                </div>
                <div class="modal-body">
                  <p>
                    Username: {{ u.username }}
                    Firstname: {{ u.first_name }}
                    Lastname: {{ u.last_name }}
                  </p>
                </div>
                <div class="modal-footer">
                  <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
              </div>

            </div>
          </div>
模板

from classwork_app import views

app_name = 'classwork_app'

urlpatterns = [
    path('', views.users, name='users'),
]
<table class="table table-bordered">
            <tr>
              <th>S/N</th>
              <th>Username</th>
              <th>Firstname</th>
              <th>Lastname</th>
              <th colspan="2">Action</th>
            </tr>

            {% if users %}
              {% for u in users %}
                <tr>
                  <td>{{ forloop.counter }}</td>
                  <td>{{ u.username }}</td>
                  <td>{{ u.first_name }}</td>
                  <td>{{ u.last_name }}</td>
                  <td style="font-size: 12px"><a data-toggle="modal"  href="#MyModal{{ u.id }}"><i class="fa fa-eye"></i></a></td>
                </tr>
              {% endfor %}
            {% endif %}

          </table>

          <div id="#MyModal{{ u.id }}" class="modal fade" role="dialog">
            <div class="modal-dialog">

              <!-- Modal content-->
              <div class="modal-content">
                <div class="modal-header">
                  <button type="button" class="close" data-dismiss="modal">&times;</button>
                  <h4 class="modal-title">{{ u.first_name }} {{ u.last_name }}</h4>
                </div>
                <div class="modal-body">
                  <p>
                    Username: {{ u.username }}
                    Firstname: {{ u.first_name }}
                    Lastname: {{ u.last_name }}
                  </p>
                </div>
                <div class="modal-footer">
                  <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
              </div>

            </div>
          </div>

序列号
用户名
名字
姓氏
行动
{%if用户%}
{用户%%中的u为%0}
{{forloop.counter}}
{{u.username}
{{u.名字}
{{u.last_name}}
{%endfor%}
{%endif%}
&时代;
{{u.first_name}{{u.last_name}}

用户名:{{u.Username}
名字:{u.first_name}
姓氏:{{u.last_name}

接近
您可以尝试将模式html代码放入for user迭代器中。通过这种方式,它将为列表中的每个用户加载一个包含用户内容的模式(如果您有大量数据,则不太推荐,可能会导致性能问题)

我只是一个新手,仍在学习,因此请在此处否决我,但您在定义
u
循环之外使用
u
u
是否在
{%endfor%}
之后显示任何内容?是的,但我知道这不是问题所在,我的问题是如何构造视图和URL