Answer the question
In order to leave comments, you need to log in
How to use data from model in javascript files?
Why can't I get a variable in a javascript file? For example, I define a variable in the main.js
file in
this way
and it does not work.
I have to first define this variable in the HTML file and then only connect main.js to the end of the file, in this way, and only then in the main.js file can I access this "bar" variable:var bar = "{{ user.username }}"
<script src="/static/demo/js/main.js"></script>
Answer the question
In order to leave comments, you need to log in
Obviously because JS files are not rendered by the Django template engine.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question