这个问题我已经有一段时间了,我一直在尝试将我的 CSS 文件到处移动并更改设置,甚至弄乱媒体 url 的东西,我不相信我现在应该这样做阅读其他问题。
我的 CSS 文件位于 /home/justin/test/static/ 目录中。我的模板位于 /test/templates 目录中。
我的设置是:
STATIC_ROOT = '/home/justin/test/static/'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
'/home/justin/test/static/',
)
我的网址是:
urlpatterns = patterns('',
url(r'^$', 'views.home'),
# Static Files
url(r'^static/(?P<path>.*)$','django.views.static.serve', {'document_root':settings.MEDIA_ROOT}),
)
我的主模板中有这三个。
<link rel="stylesheet" href="/static/style.css" />
<link rel="stylesheet" href="{{ STATIC_URL }}style.css" />
<link rel="stylesheet" href="{{ STATIC_URL }}/style.css" />
他们出来了:
<link href="/static/style.css" rel="stylesheet"></link>
<link href="style.css" rel="stylesheet"></link>
<link href="/style.css" rel="stylesheet"></link>
第一个输出到正确的文件,但它不起作用。非常感谢任何帮助。谢谢你。
我的意见.py:
from django.shortcuts import render_to_response
def home(request):
return render_to_response('index.html',{})
我的终端错误是:
[16/Aug/2013 21:00:21] "GET /static/style.css HTTP/1.1" 500 1729