How to link a javascript file in flask app ?
I try to exactly what I found in exactly similar posts, but their solution not works for me.
Default ways are not working:
<script src="/static/finances.js"></script>
or
<script src="{{ url_for('static', filename='finances.js') }}"></script>
or
<script src="./static/finances.js"></script>
This following code is in my layout.html page, and it works correctly in my Flask Application:
<script type="text/javascript">
$(document).ready(function() {
$("#category").change(function() {
$.ajax({
type: "POST",
url: "{{ url_for('load_subcategories') }}",
data: {cat: $(this).val()},
success: function(data) {
$("#subcategory").html(data);
}
});
});
$("input[name=type]").change(function() {
$.ajax({
type: "POST",
url: "{{ url_for('load_categories') }}",
data: {type: $('input[name="type"]:checked').val()},
success: function(data) {
$("#category").html(data);
}
});
});
});
</script>
But, when I decide to put in a javascript file inside <header>
and after jquery.js, it does not work! (the problem)
I already checked a similar problem in another stackoverflow link, but no success yet.
My Flask app is structured like this in directory-site/
run.py
app/
templates/
layout.html
...
static/
finances.js