Answer the question
In order to leave comments, you need to log in
How to pass static to js file (Django)?
There is a code in JS:
$('.prof-button').mouseenter(function(){
$('.prof-button').attr('src','/themes/choosevuz/images/main-menu-buttons-profs-active.png')
});
$('.prof-button').mouseleave(function(){
$('.prof-button').attr('src','/themes/choosevuz/images/main-menu-buttons-profs.png')
});
attr()
How to pass the image URL
as the second argument ? {% static "расположение картинки в папке статики" %}
Answer the question
In order to leave comments, you need to log in
The issue was solved trivially simply:
the second argument can simply be passed the path to the file, without static.
The general approach is that before connecting the js file that displays the image, you insert the following html
<script>
var pathToImage = '{% static "расположение картинки в папке статики" %}';
</script>
<script src="some-main.js"></script>
The easiest way is to put the script in a Django html template and load it with
{% extends ... %}
{% block % ...}{% endblock %}
You can also load it through a template in a JavaScript variable {{ STATIC_URL }} and use it in other scripts
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question