
现在有个django blog。我想用户可以设置meta的信息。
<title>{{detals.title}}</title>
<meta name="description" cOntent="{{detals.description}}" />
<meta name="keywords" cOntent="{{detals.keywords}}">
<link rel='next' href='{{detals.url}}/about/' />
<link rel="canonical" href="{{detals.url}}" />
<meta property="og:title" cOntent="{{detals.name}} - {{detals.url}}" />
<meta property="og:type" cOntent="blog" />
<meta property="og:url" cOntent="{{detals.url}}" />
例如这样。请问要具体怎么做。。真心纠结这个问题。先谢谢!
1 CodeDrift OP 这写信息写在base.html页面里面。可是怎么才能在后台渲染给base.html呢。 好像没有专门要去渲染base页面的 一般都是index.html什么的 |
2 zenxds 2015-05-20 11:06:51 +08:00 把用户设置的信息作为数据传入就行了,base里面一般用block包上,在子页面重写 |
4 zenxds 2015-05-20 11:16:25 +08:00 @Anybfans 你可以单独写一个模板去extend base,然后跟用户相关的页面去extend这个模板,如果你所有页面都想这么设置那就直接写在base |
5 CodeDrift OP @zenxds 对呀。可是怎么数据怎么渲染给base.html呢。。。还是不懂。。 例如我现在后台已经得到这个数据了。。怎么渲染给Base页面呢 |
7 glasslion 2015-05-20 13:39:23 +08:00 django template 是可以继承和覆盖的 base.html: <head> {% block hello %} <title> xxx</title> {% endblock %} </body> </head> details.htm {% extends "base.html" %} {% block head %} {{ block.super }} <meta property="..." /> {% endblock %} |
10 zq9 2015-05-20 14:37:24 +08:00 |