我在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
文件夹存在。但是不知何故静态文件没有被提供。
答案 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/'}),