pay*_*ike 11 html string django render django-templates
我想要的是堆栈溢出.用户可以HTML格式化他们的文本输入,页面应该以完全相同的方式呈现,
我wmd.js用来存储格式化的输入,考虑我有一个{{variable}}带字符串值的上下文变量"<p>something</p>".当我渲染模板时,
{{variable}} outputs <p>something</p>
and {{variable|safe}} also output <p>something</p>
Run Code Online (Sandbox Code Playgroud)
它将html标记显示为页面中的文本.如何在HTML标记中呈现{{variable}}但不以纯文本形式显示它们.
模板
<div id='thread_answer_content' >
{% for answer in question.answer_set.all %}
{{answer.answerbody|safe}}
{% endfor %}
</div>
Run Code Online (Sandbox Code Playgroud)
风景
def detail(request,question_id):
q = get_object_or_404(Question,pk=question_id)
return render_to_response('CODE/detail.html',{'question':q},
context_instance = RequestContext(request)
)
Run Code Online (Sandbox Code Playgroud)
这里是问题的django管理页面,顺便说一句,我使用的是sqlite3

Pat*_*g J 20
使用标签:http://docs.djangoproject.com/en/dev/ref/templates/builtins/#autoescape
{% autoescape off %}{{ variable }}{% endautoescape %}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11634 次 |
| 最近记录: |