Pregunta

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?

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top