python - Import javascript files with jinja from static folder -
i need have access jinja template in javascript files (due i18n tags). way found load js file include, jinja method. {% include "file.js" %}
however method files in templates folder. js files must in static folder. question is, how can change way how jinja looks files? instead of search in templates folder, in case, search in static folder.
{% block javascript %} <script type="text/javascript"> {% include "myscript.js" %} </script> {% endblock %}
given example directory structure looks this
app/static/css/bootstrap.min.css app/static/js/bootstrap.min.js app/templates/test_page.html app/views run_server
you can set flask static_url_path
when create app object
app = flask(__name__, static_url_path='/static')
and in test_page.html
can have looks this
<link href="{{ url_for('static', filename='css/bootstrap.min.css') }}" rel="stylesheet"> i'm html body <script src="{{ url_for('static', filename='js/bootstrap.min.js') }}"></script>
wiki
Comments
Post a Comment