【发布时间】:2012-08-16 01:13:58
【问题描述】:
由于某种原因,django 没有提供我的静态文件。
我已经查看了很多解决此问题的方法,但我仍然没有找到解决方案。
这是我的配置:
urls.py
urlpatterns = patterns('',
(r'^$', index),
(r'^ajax/$', ajax),
(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': path.join(path.dirname(__file__), 'static')}),
)
settings.py
STATIC_ROOT = '/home/aurora/Code/django/test/static/'
STATIC_URL = '/static/'
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)
当我导航到http://localhost:8000/static/css/default.css
我收到此错误:'css/default.css' could not be found
当我导航到http://localhost:8000/static/
我收到此错误:Directory indexes are not allowed here.
看起来静态目录正在映射,但子目录没有。
【问题讨论】:
-
请在此处查看我的答案:stackoverflow.com/questions/9168187/…。总而言之,您不会将静态文件存储在
STATIC_ROOT中。 Django 从不 在开发中使用这个目录。即使在生产环境中,从这个目录中提供服务的是您的网络服务器而不是 Django。 -
立即工作。如果您希望我标记为答案,请发布为答案。