0

It was working fine before, and I have no clue what changed but I'm getting errors now with static files loading =( Please help!

Using Django 1.4

Urls.py

from django.contrib.staticfiles.urls import staticfiles_urlpatterns
urlpatterns += staticfiles_urlpatterns()

Settings.py

STATIC_ROOT = '/root/abc/abc_app/sitestatic'

# URL prefix for static files.
STATIC_URL = '/static/'

# Additional locations of static files
STATICFILES_DIRS = (
    '/root/abc/static/',
    '/Users/blahusername/djangoproj/abc/static/',
)

Header.html

  <script type="text/javascript" src="/static/js/jquery-1.7.1.min.js"></script>

Errors in browser:

GET file://localhost/static/js/jquery-1.7.1.min.js  
Unsafe JavaScript attempt to access frame with URL file://localhost/Users/blahusername/djangoproj/abc/abc_app/templates/index.html from frame with URL http://www.youtube.com/embed/yyy. Domains, protocols and ports must match.
user1678031
  • 2,925
  • 2
  • 16
  • 15

1 Answers1

0

This does not look like a django-staticfiles problem based on the browser error you have shown, but an issue with browser cross-origin policy / iframe and host page access. To confirm that:

  • In a browser that has devtools ( eg Chrome or Safari ), load the page that is causing the error.
  • Click on the "Resources" tab and under Frames > ( name of your primary frame ) > Scripts look for the jquery script.
  • Reload the page after clicking on the network tab and check for the HTTP Status of the request for the jQuery file.

If you can see the jquery-1.7.1.min.js file contents in the resources tab, and the request to load it has a status of 200 or 304 in the network tab, then the problem is not in django's static file serving.

Another observation:

  • the index.html URL in your browser error is a file:/// url ( file://localhost/Users/blahusername/djangoproj/abc/abc_app/templates/index.html ). Due to cross-origin resource sharing constraints, most browsers will usually not allow a page loaded from one origin to access resources from a different origin. Each file:/// URL is treated as different from every other file:///, even if both refer to resources that are in the same filesystem folder.
Ngure Nyaga
  • 2,989
  • 1
  • 20
  • 30