i have a flask project and use jinja2 template engine, in template part: i make a base.html like this:
{%- block styles %}
{% include 'static_partial/style.html' %}
{%- endblock styles %}
<body{% block body_attribs %}{% endblock body_attribs %}>
{% block body -%}
<div class="container">
{% block navbar %}
{% include 'navbar.html' %}
{%- endblock navbar %}
{% block scripts %}
{% include 'static_partial/script.html' %}
{%- endblock scripts %}
</div>
{%- endblock body %}
</body>
{%- endblock html %}
</html>
i import js and css files in a partial directory, and the navbar.html also.
and in navbar.html, i have some css and js definition in itself, where should i put the narbar.html css and js definition? if i put it in navbar.html, it will cause error because the js need to load some js file from base.html first, it confused me for a long time....
the project structure is like this:
├── station
│ ├── static
│ ├── templates
│ ├── py
my scripts.html is like this:
<!-- jQuery2 -->
<script src="//cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>
<!-- BootStrap Plugins -->
<script src="//cdn.bootcss.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<!-- Global JS -->
<script src="{{ url_for('static', filename='assets/js/global.js')}}"></script>
and then i include this file in my base.html
Unless I am missing something, you can add another js file for your navbar's JavaScript under assets/js
ie navbar.js
.
The add it as another script tag in scripts.html
:
<script src="{{ url_for('static', filename='assets/js/navbar.js')}}"></script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.