3

In my settings.py I have set the staticfiles_dirs as so

STATICFILES_DIRS = (
    os.path.abspath(os.path.join(os.path.dirname( __file__ ), '..', 'static')).replace('\\','/') 
)

and in the folder myproject/static I have a file called jquery-1.10.0.js. I have tried to load the file in my app's template like this

{% load static %}

<script type="text/javascript" src="{% static "jquery-1.10.0.js" %}"></script>

but I cannot access the jquery functions from within my template and if I go to the url that {% static "jquery-1.10.0.js" %} returns, which is /static/jquery-1.10.0.js, I get a page that says A server error occurred. Please contact the administrator.

How do I access the jquery file from within the template?

bab
  • 2,119
  • 3
  • 28
  • 49
  • 1
    Which version of Django? Is debug mode on? Any error on the console? – Bibhas Debnath May 26 '13 at 19:48
  • can you not just do `/static/jquery-1.10.0.js`? –  May 26 '13 at 20:46
  • Check these: http://stackoverflow.com/questions/16554845/loading-images-in-a-static-file/16554949#16554949 http://stackoverflow.com/questions/16389989/static-files-are-not-loaded-in-django/16390679#16390679 http://stackoverflow.com/questions/16615224/i-cant-define-staticfiles-dirs-using-python-to-figure-out-the-path/16615325#16615325 – Paulo Bu May 26 '13 at 22:17

1 Answers1

2

This is kind of silly but the reason I couldn't access the static file was because I didn't add a comma to the end of the first element in the staticfiles_dirs tuple.

The reason it didn't work in the first place was because a comma was needed at the end in order for python to recognize the staticfiles_dirs variable as a tuple.

bab
  • 2,119
  • 3
  • 28
  • 49