您的问题是您无法在urls.py中的任何地方收听URL“ / static /”
如果您通过apache或Nginx之类的网络服务器为应用程序提供服务,那么这是正常现象,因为该网络服务器将处理静态文件本身。
为了进行开发,Django带有内置的静态服务器
到urls.py,最后添加
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
urlpatterns += staticfiles_urlpatterns()
这样做是添加/ static /网址,并让您在没有网络服务器的情况下提供服务。
这相当于
url(
regex=r'^static/(?P<path>.*)$',
view='django.views.static.serve',
kwargs={'document_root': settings.STATIC_ROOT,}
)
some people will tell you that you need to wrap the URL-rules in a “if settings.DEBUG” to use the dev-only rules, but this isnt needed at all and actually i find that to be a bad advice.