Extending Django Flatpages to accept template tags

后端 未结 2 2147
再見小時候
再見小時候 2020-12-28 22:45

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.

I found this snippet but after

相关标签:
2条回答
  • 2020-12-28 23:21

    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>
    
    0 讨论(0)
  • 2020-12-28 23:22

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

    0 讨论(0)
提交回复
热议问题