I've got a view func like this:
def user_agreement(request):
return response(request, template='misc/flatpage.html',
vars={'fp':FlatPage.objects.get(key='user-agreement')})
And then the template looks like this开发者_开发问答:
<h2>{% block title %}{{ fp.title }}{% endblock %}</h2>
{{ fp.content|markdown }}
This works pretty well, but I also want to include some Django {{filters}}
in the content. Is there an "evaluate" filter so I can do:
{{ fp.content|evaluate|markdown }}
And it will substitute all my variables for me? Or what's the easiest/best approach to this?
I'm not sure if I understand your question correctly, but the following might work.
Treat flatpage.content
as a template, and render it in the view with any context you wish.
# view
from django.template import Template, Context
def user_agreement(request):
flatpage = FlatPage.objects.get(key='user-agreement')
t = Template(flatpage.content)
fp_content = t.render(Context({}))
return response(request, template='misc/flatpage.html',
vars={'title': flatpage.title, 'content': fp_content})
Then apply the markdown filter in the misc/flatpage.html
template.
<h2>{% block title %}{{ title }}{% endblock %}</h2>
{{ content|markdown }}
精彩评论