Bootstrap modals not showing correctly when using Jinja templates

若如初见. 提交于 2021-01-28 08:43:58

问题


While using Jinja templates, Bootstrap modals do not show properly. Either they show without disabling the background or they show disabled (and can't be closed). Including a CSS z-index didn't work. Changing the JavaScript code to open the modal manually didn't work.


回答1:


All modals need to be placed outside of your <body>. If you place the modals inside of your main jinja2 {%block content%}, they have a tendency to behave oddly. Try the following:

template.html- this is your main jinja2 template

<!DOCTYPE html>
    <html lang="en">
        <head>
        enter code here
        </head>

        <body>
          {% block content %}
          {% endblock %}
        </body> 

        {%block modals%}
        {%endblock%}

</html>

Then on your child page, include the html below at the bottom of the page, after {%endblock content%}:

{%block modals%}
<!-- Your modals go here -->
{%endblock%}


来源:https://stackoverflow.com/questions/57658148/bootstrap-modals-not-showing-correctly-when-using-jinja-templates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!