【问题标题】:show django-bootstrap modal on any page load在任何页面加载时显示 django-bootstrap 模式
【发布时间】:2019-05-13 20:56:43
【问题描述】:

我正在尝试使用 django-bootstrap4 模式作为 nag 框来接受隐私政策。

(我有一个自定义模板过滤器来检查这是否已经被接受。我不担心那一点)

它应该在导航到新页面时打开。我试过this solution,但模式是不可关闭的,即使是关闭按钮也是如此。它也不会影响它背后的页面。

  • 我已经使用 <link href="/static/css/auto_modal.css" rel="stylesheet"> 导入了自定义 css,使用 django-bootstrap 时是否正确?

  • 模式的代码在 base.html 模板中。是否可以将其放入仅用于模态的单独模板中?

【问题讨论】:

  • 您应该使用<link href="{% static 'css/auto_modal.css' %}" rel="stylesheet"> 正确链接您的静态文件
  • 谢谢。它没有解决我遇到的问题,但我很高兴知道正确的方法。

标签: django bootstrap-4 django-bootstrap4


【解决方案1】:

我使用了 Javascript

static/js/ 文件夹中创建一个 my_javascript.js 文件,其中包含

$(document).ready(function () {
     $("#ConfirmGDPRModal").modal('show');
     console.log();
});

使用

将其加载到 base.html 模板中
<script src="{% static 'js/auto_modal.js' %}"></script>

然后像往常一样创建您的模态。 我仍在考虑将其放入单独的 html 文件中。

【讨论】:

    猜你喜欢
    • 2013-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-25
    • 2021-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多