reK*_*DLE 5 css django django-templates
我正在尝试通过我的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根本没有读取它.我想我的一切都很体面; 我在这里和这里寻找提示.有人有想法吗?
生成的样式表是否使用正确的 mime 类型?如果不是,浏览器可能不会将其解释为 CSS。
\n\n我无法记住是否render_to_response接受content_type=\'text/css作为参数,但是如果 Django 已经使用正确的 mime 类型,则有一种方法可以设置它。
编辑:正如@TommasoBarbugli 指出的,你想要mimetype的参数render_to_response。
(Firefox\xe2\x80\x99s Firebug 插件或 Chrome/Safari 中的 Web Inspector 应该能够向您显示 stylesheet\xe2\x80\x99s mime 类型。)
\n| 归档时间: |
|
| 查看次数: |
1274 次 |
| 最近记录: |