2017-06-15 35 views
0

我正在使用simplemde markdown编辑器,它将markdown元素添加到用户内容,我的问题是当用户输入下面一行时,使用stakedit的块(** text **)和代码(4个空格)我想它显示如下格式Django格式化输入内容

此程序无法运行

#include<iostream> 
int main() 
{ 
    cout<<"Hello world" 
} 

但是当我保存的内容和逃避它,我得到以下输出

此程序无法正常工作的#include INT主要(){COUT < <的“Hello world”}

在未格式化的方式

,我该如何将其显示为格式化 下面是我使用的显示代码:

{% block content %} 
{% if question_detail %} 
<h4><small> {{ question_detail.title }} </small></h4> 
<pre> {{ question_detail.get_description|escape |linebreaksbr }} </pre> 
{% else %} 
<small > an error occured </small> 
{% endif %} 
{% endblock %} 

get_description在models.py

def get_description(self): 
    return mark_safe (markdown(self.description)) 
+0

尝试删除'|越狱| linebreaksbr'过滤器是因为你已经迎来降价输出作为安全 – SebCorbin

+0

这样做....但仍然代码是越来越印在未格式化的方式。 –

回答

0

HTML

{% block content %} 
{% if question_detail %} 
<h4><small> {{ question_detail.title }} </small></h4> 
<pre> {{ question_detail.get_description|safe }} </pre> 
{% else %} 
<small > an error occured </small> 
{% endif %} 
{% endblock %} 

Views.py

def get_description(self): 
    return markdown(self.description) 
+0

不,没有工作。 –