2012-10-09 68 views
0

它以前工作正常,我不知道是什么改变了,但我发现错误,现在的静态文件加载=(请帮帮忙!Django的静态CSS JS图像文件不加载

使用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> 

错误的浏览器:

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. 
+0

你可以执行命令:python manage.py findstatic js/jquery-1.7.1.min.js?什么是输出? –

+0

在此处找到'js/jquery-1.7.1.min.js': /Users/blahusername/djangoproj/abc/static/js/jquery-1.7.1.min.js – user1678031

回答

0

这看起来并不像基于浏览器的错误,你都表现出了Django的staticfiles问题,但随着浏览器跨域策略/ iframe和主机的问题页面访问。要确认:

  • 在具有devtools(例如Chrome或Safari)的浏览器中,加载导致错误的页面。
  • 点击“资源”选项卡,并在框架>(您的主框架的名称)>脚本查找jquery脚本。
  • 点击网络选项卡后重新加载页面,并检查jQuery文件请求的HTTP状态。

如果您可以在资源选项卡中看到jquery-1.7.1.min.js文件内容,并且加载它的请求在网络选项卡中的状态为200或304,则问题不在于在django的静态文件服务中。

另一种看法:

  • 在浏览器中的错误中的index.html URL是一个文件:/// URL(文件://本地主机/用户/ blahusername/djangoproj/ABC/abc_app /模板/指数.html)。由于跨源资源共享的限制,大多数浏览器通常不允许从一个来源加载的页面访问来自不同来源的资源。每个文件:/// URL被视为不同于其他每个文件:///,即使这两个文件都引用同一个文件系统文件夹中的资源。