In the following Image of code, I am trying to reference the javascript file "doggies.js" that is currently in the basket folder. This happens on the click of a button on my website, but every time it says it cannot find the file. I have tried ../doggies.js as well but this does not work, is there any reason as to why this might be happening?
<script type="text/javascript">
$(document).on('click', '.checkout-button', function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "doggies.js";
document.getElementsByTagName("head")[0].appendChild(script);
return false;
console.log("yo")
})
</script>
Here is the error
Not Found: /basket/doggies.js
[13/May/2021 18:50:22] "GET /basket/doggies.js HTTP/1.1" 404 3322
asked May 13, 2021 at 18:57
alborzdev
551 gold badge1 silver badge6 bronze badges
-
Are you using Django framework?pullidea-dev– pullidea-dev2021年05月13日 19:00:58 +00:00Commented May 13, 2021 at 19:00
-
@Sophie yes I am using Django, does that affect things?alborzdev– alborzdev2021年05月13日 19:04:27 +00:00Commented May 13, 2021 at 19:04
-
how do you import the file? share pleaseSırrı Kırımlıoğlu– Sırrı Kırımlıoğlu2021年05月13日 19:09:58 +00:00Commented May 13, 2021 at 19:09
1 Answer 1
Create static folder in your root directory add this line to settings.py
STATIC_URL = '/static/'
And load STATIC in your html file and use static to load the javascript files.
{% load static %}
{% static 'js/doggies.js' %}
answered May 13, 2021 at 19:10
pullidea-dev
1,7981 gold badge9 silver badges24 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
pullidea-dev
Can you check my answer then? 😊
pullidea-dev
Thanks. Let`s keep in touch.
default