I had my static files working correctly until I tried to add this library https://github.com/ierror/django-js-reverse
I followed the instructions from the page, but Django still can't find the new resource.
from settings.py
STATIC_ROOT = 'staticfiles'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static/'),
)
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_js_reverse',
...,
)
in my template
<script src="{% static 'django_js_reverse/js/reverse.js' %}"></script>
my directory structure looks like this
staticfiles/
admin/
dist/
django_js_reverse/
js/
reverse.js
After running
python manage.py collectstatic
python manage.py runserver
I also tried to run the following according to the library instructions, but no luck
./manage.py collectstatic_js_reverse
Here's the output from runserver when I try to load the page.
[08/Mar/2015 19:12:33] "GET /static/custom.css HTTP/1.1" 304 0
[08/Mar/2015 19:12:33] "GET /static/dist/css/bootstrap.min.css HTTP/1.1" 304 0
[08/Mar/2015 19:12:33] "GET /static/django_js_reverse/js/reverse.js HTTP/1.1" 404 1697
[08/Mar/2015 19:12:33] "GET /static/dist/js/bootstrap.min.js HTTP/1.1" 304 0
[08/Mar/2015 19:12:33] "GET /static/csrf.js HTTP/1.1" 304 0
[08/Mar/2015 19:12:33] "GET /static/custom.js HTTP/1.1" 304 0
I can't figure out where the issue is. The static files settings are obviously set up correctly because all the other files are being loaded fine. I must be missing something obvious. Any help would be appreciated\
UPDATE
I tried moving the reverse.js file to dist/ but it still returns a 404.
The permissions on all the files are the same
ls -la staticfiles/dist/js
-rw-r--r-- 1 adam staff 67155 Mar 8 15:06 bootstrap.js
-rw-r--r-- 1 adam staff 35601 Mar 8 15:06 bootstrap.min.js
-rw-r--r-- 1 adam staff 484 Mar 8 15:06 npm.js
-rw-r--r-- 1 adam staff 3258 Mar 10 10:31 reverse.js
collectstatic
won't help if you are runningrunserver
. Isstaticfiles
yourSTATIC_ROOT
or one ofSTATICFILES_DIRS
? Try copying thereverse.js
file intodist
, change the script src accordingly and check if that works..gitignore
?urlpatterns = patterns('', url(r'^jsreverse/$', 'django_js_reverse.views.urls_js', name='js_reverse'), )
to your urls.py?