我正在尝试通过我的url.py文件提供CSS文件,因此我可以在CSS中使用模板标记.
这是我的代码.
base.html文件:
<head>
...
<link rel="stylesheet" type="text/css" href="/site_media/css/wideTitle.css" />
Run Code Online (Sandbox Code Playgroud)
urls.py:
(r'^site_media/css/wideTitle.css','lightbearers.views.viewWideTitle'),
Run Code Online (Sandbox Code Playgroud)
views.py:
def viewWideTitle(request):
contentListAbout = About.objects.filter(Q(startDate__lte=datetime.now())).order_by('-startDate')
if len(contentListAbout) > 0:
contentAbout = contentListAbout[0]
else:
contentAbout = None
...
return render_to_response('wideTitle.css', {'contentAbout':contentAbout, ...},
context_instance=RequestContext(request))
Run Code Online (Sandbox Code Playgroud)
settings.py:
TEMPLATE_DIRS = (
os.path.join(PROJECT_PARENT, "templates"),
os.path.join(PROJECT_PARENT, "media/css"),
)
Run Code Online (Sandbox Code Playgroud)
wideTitle.css(在/ media/css中):
#wideTitle{
clear:both;
height:180px;
padding-left:0px;
background: url({{ contentAbout.headerImage.url }}) no-repeat top left;
}
Run Code Online (Sandbox Code Playgroud)
我可以通过在浏览器中输入其URL来访问CSS文件,但Base.html根本没有读取它.我想我的一切都很体面; 我在这里和这里寻找提示.有人有想法吗?