【发布时间】:2012-08-19 11:08:27
【问题描述】:
我已按照this question、the documentation 中的说明进行操作,甚至查看了this one,但到目前为止,我无法使用python manage.py runserver 获取我的静态文件。
这些是我的(相关?)设置:
STATIC_ROOT '/home/wayne/programming/somesite/static'
STATICFILES_DIRS ('/home/wayne/programming/somesite/static/styles',
'/home/wayne/programming/somesite/static/admin')
在我的 urls.py 中:
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
# The rest of my urls here...
if settings.DEBUG:
urlpatterns += staticfiles_urlpatterns()
我的 base.html 中有以下代码
<link rel="stylesheet" type="text/css" href="{% static "styles/main.css" %}">
{% block styles %}
{% for sheet in styles %}
<link rel="stylesheet" type="text/css" href="{% static sheet %}">
{% endfor %}
我保证我不会产生幻觉:
(.env)wayne:~/programming/somesite/static$ pwd
/home/wayne/programming/somesite/static
(.env)wayne:~/programming/somesite/static$ ls
admin styles
但是,当导航到http://localhost:8000/ 时,我的网站缺少样式表,当我转到http://localhost:8000/static/styles/main.css 时,我得到'styles/main.css' could not be found,并尝试导航到localhost:8000/static/ 或localhost:8000/static/styles,它告诉我目录不允许使用索引。
我在这里错过了什么?
【问题讨论】:
-
stackoverflow.com/a/9613606/344286 实际上回答了我的问题 - 但从其他任何问题/文档中都不是很清楚,所以我认为(除非这个问题真的是重复的)它可能对其他人有帮助伙计们。如果没有人提出一个好的答案,我很快就会自己写一个。
-
您的情况与链接问题中 Mohammed 的情况完全相同,但您提供了更多信息,而且您似乎尝试了更多事情。跨度>