小编reK*_*DLE的帖子

正确使用CSS文件中的模板语言

我正在尝试通过我的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根本没有读取它.我想我的一切都很体面; 我在这里这里寻找提示.有人有想法吗?

css django django-templates

5
推荐指数
1
解决办法
1274
查看次数

标签 统计

css ×1

django ×1

django-templates ×1