Django没有提供一些静态文件

时间:2012-08-11 14:07:44

标签: django django-staticfiles

我在Django面临一个非常奇怪的问题,STATIC_URL/static/我已经使用pip作为-e git+git://github.com/foo/bar.git#egg=bar安装了应用它将它加载到virtualenv src文件夹中。

现在,我尝试将与此应用相关的静态文件作为/static/bar/js/something.js获取,并且src文件夹中有一个bar/bar/static/bar/js/something.js文件。即使我findstatic bar/js/something.js,它也会为我提供该文件的有效路径。但是,当我使用浏览器访问它时,我是301到/static/bar/js/something.js/ 404s。

为什么会这样?

即使使用staticfiles应用程序,我也能看到它识别我的应用已安装且其static文件夹存在。但是不知何故静态文件没有被提供。

2 个答案:

答案 0 :(得分:3)

确保您拥有set up the django development server to actually server the static files for you

<强> urls.py

from django.contrib.staticfiles.urls import staticfiles_urlpatterns
# ... the rest of your URLconf goes here ...
urlpatterns += staticfiles_urlpatterns()

答案 1 :(得分:1)

尝试使用此urlpattern:

 url( r'(?P<path>.*)$', 'django.views.static.serve', {'document_root': '/path/to/file/'}),