1๐
*The html page lives in my template folder and in this folder, I have also folder like scripts/spryMap-2.js
You should not have your static files (eg spryMap-2.js) in your templates folder. It should go in your static files folder. Then you load your script with something like this
<script type="text/javascript" src="{{ STATIC_URL }}scripts/spryMap-2.js"></script>
Update: Iโm not sure why my answer was down voted. Iโve expanded my answer to provide more detailed instructions for fixing your static files.
The problem is your static files are not being served correctly โ hence the 404 when you try to access the js file directly. As I mentioned above, the templates folder is not the right place for static files. You should configure your STATIC_ROOT
and STATIC_URL
settings. For example
#Make this the path to the folder where you will keep your static files
STATIC_ROOT = '/path/to/your/project/static'
#The absolute or relative URL which will serve your static files
STATIC_URL = '/static/' #translates to http://localhost:8000/static/, for example
and to get the django development server to serve your static files you will need the following in your urls.py
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
# ... the rest of your URLconf goes here ...
urlpatterns += staticfiles_urlpatterns()
0๐
I just checked this code and it seems to be working fine, perhaps try checking the script source path tag. I used
<script src="{{ STATIC_URL }}assets/js/spryMap-2.js"></script>
instead of
<script type="text/javascript" src="scripts/spryMap-2.js"></script>
and i got the attached output which is draggable:
Incase you are using Django make sure you mention the correct path in the settings file for the static path and put your sprymap.js file to that location, i guess this will sort the problem.
- [Answer]-How to to retrieve the SQL type of the primary key of a related field mapped by Django's ORM
- [Answer]-Pip installing dj_static, import error
- [Answer]-How to get Django form method to not 500 when debug is false on raising a form error?
- [Answer]-Django: can "double" 'render_to_response' be unified into only one view?