扩展Django Flatpages以接受模板标签 [英] Extending Django Flatpages to accept template tags

查看:112
本文介绍了扩展Django Flatpages以接受模板标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用django平板纸在我们的网站上的很多内容,我想扩展它接受内容中的django模板标签。

I use django flatpages for a lot of content on our site, I'd like to extend it to accept django template tags in the content as well.

我发现这个代码段,但经过很多的讨价还价,我无法让它上​​班。我正确地假设你还需要子类django平板应用程序来使其工作吗?这是最好的做法吗?我不太清楚如何构造它,因为我不想直接修改django发行版。

I found this snippet but after much larking about I couldn't get it to work. Am I correct in assuming that you would need too "subclass" the django flatpages app to get this to work? Is this best way of doing it? I'm not quite sure how to structure it, as I don't really want to directly modify the django distribution.

推荐答案

1。一个简单的页面视图将通过加载每个页面的模板来呈现模板标签:

1. A simple page view wich will render template tags by loading a template for each page:

url.py

url(r'^page/(?P<slug>.*)/$','my_app.views.page_detail', name='page_url'),

my_app / views.py

def page_detail (request, slug):
    return render_to_response('page/' + slug + '.html', {},
                              context_instance=RequestContext(request))

2。数据库,是在您的模板中使用模板评估标签,如这个

2. Another method with flat pages stored in database, is to use a "template evaluation tag" in your template like this one.

编辑你只需要修改平板模板,如下所示:

edit You just have to modify flatpages template like this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
    "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<title>{{ flatpage.title }}</title>
</head>
<body>
{% load evaluate_tag %} 
{% evaluate flatpage.content %} 
</body>
</html>

这篇关于扩展Django Flatpages以接受模板标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆