show django-bootstrap modal on any page load

848 Views Asked by At

I am trying to use a django-bootstrap4 modal as a nag box to accept a privacy policy.

(I have a custom template filter to check whether this has already been accepted. I am not worried about that bit)

It should open whenever navigating to a new page. I have tried this solution, but the modal is not dismissable, not even with a close button. Neither does it shadow the page behind it.

  • I have imported the custom css using <link href="/static/css/auto_modal.css" rel="stylesheet">, is this correct when using django-bootstrap?

  • The code for the modal is in the base.html template. Is it possible to take it into a seperate template just for the modal?

1

There are 1 best solutions below

0
Escatologist On

I resorted to Javascript

make a my_javascript.js file in a static/js/ folder, containing

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

load it into the base.htmltemplate with

<script src="{% static 'js/auto_modal.js' %}"></script>

Then create your modal as usual. I'm still looking into getting this into a seperate html file.