[Answered ]-Unable to print the username onto console in JavaScript

1👍

According to the w3 organization, if a <script> tag has a src="…" attribute, the content of the script is ignored, so it will never evaluate var user= …. You should work with two tags:

<script src="{% static 'js/cart.js' %}"/>
<script>
  var user = '{{request.user}}';
</script>

if js/cart.js needs to user the user variable, you need to define that first, so:

<script>
  var user = '{{request.user}}';
</script>
<script src="{% static 'js/cart.js' %}"/>

0👍

I would recommend to add a breakpoint in your browser debugger in the line

var user=...

and reload the page.
Thus you can see if the line is executed before the card.js script.

Leave a comment