[英]How to pass the correct information to Django modal in templates
因此,我能够创建一个列表,其中列出了在 Django 模板中向特定用户发送消息的所有发件人,但我想做的是,当用户单击查看按钮时,应该弹出一个模式并显示消息是。 举个例子。 如果我单击“XYZ 向您发送了一条消息”,我应该能够在弹出模式中看到该消息是什么。
我写的 HTML 代码:
{%for elements in messages %}
<ul class="list-group shadow p-3">
<li class="list-group-item">
<img src="{{elements.sender.userprofile.profile_pic.url}}" width="40px" height="40px">
{{elements.sender}} sent you a message
</li>
<button data-toggle="modal" data-id="{{ elements.pk }}" data-target="#myModal1" class="open-my-modal">
View
</button>
</ul>
{%endfor%}
应该显示消息的模态。
<div class="modal" id="myModal1">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">Ending Survey</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div class="modal-body">
{{elements.message1}}
<h5>here mate</h5>
</div>
</div>
</div>
</div>
我试过无数种方法。 谢谢和问候
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.