开发者

Django templates, pass template language through a template variable

开发者 https://www.devze.com 2023-02-11 06:05 出处:网络
I was thinking about putting my static pages in the database (simple model of url, title and content) and then having a basic base_static.html template - making them super easy to edit (from admin int

I was thinking about putting my static pages in the database (simple model of url, title and content) and then having a basic base_static.html template - making them super easy to edit (from admin interface) if necessary.

I know you can easily escape html like so:

{{ content|safe }}

or

{% autoescape off %}
{{ content }}
{% endautoescape %}

But I need to be able to use some of the template language in the 开发者_运维知识库static pages, e.g. a simple for loop to go over variables passed to it from the view.

Is this possible, or would you recommend simply using templates to serve the static pages?(They won't change that much ever)

Thank you for your help.


If you want to store templates in db (and that is what you want if you want to use a template language) you can use this app : django-dbtemplates.


Check this question: Extending Django Flatpages to accept template tags

You may get some ideas from the solution exposed there

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号