Django 消息框架呈现在 boostrap modal 中



我有一个Django应用程序。我想在用户登录后发出欢迎消息。我知道如何使用框架消息来做到这一点,但问题是我想在模态中渲染它,而不是在div 中渲染它!

我试过了:

<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
       {% if messages %}
  <ul class="messages">
    {% for message in messages %}
      <li class="{{ message.tags }}">{{ message }}</li>
    {% endfor %}
  </ul>
{% endif %}
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

但正如您可能想象的那样,它不起作用,模态不会渲染。你知道我怎样才能让它工作吗?

实际上,它不仅仅是一条欢迎信息,它是一个欢迎和一个小教程。

非常感谢你

你可以

使用Javascript或jQuery。您需要它来激活模态。

根据您的需要使用show:trueshow:false

尝试使用 :

<script type="application/javascript">
    $(document).ready(function(){
        $('#exampleModal').modal({show:true});
    });
</script>

希望对你有帮助

最新更新