Extending Django Flatpages to accept template tags

和自甴很熟 提交于 2019-11-30 04:18:27
Pierre-Jean Coudert

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

in url.py

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

in my_app/views.py

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

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>
Carles Barrobés

An alternative approach could be to write a simple app based on the direct_to_template generic view.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!