Django + markdown无法在我的服务器上呈现我的代码,但它正好在我的电脑上。
<div class="codehilite">
<pre><span></span>``
<span class="kn">import</span>
<span class="nn">numpy</span>
<span class="kn">as</span>
<span class="nn">np</span>
`<pre class="codehilite"><code>import numpy as np</code></pre>`
这是我的CSS
{% load staticfiles %}
<link rel="stylesheet" type="text/css" href="{% static 'blog/monokai.css' %}" />
{% extends "./blog/base.html" %}
{% block content %}
{% load custom_markdown %}
<div class="posts">
<h1>{{BlogPost.title}}</h1>
{{BlogPost.body|custom_markdown}}
</div>
{% endblock %}
这是我的降价设置
import markdown
from django import template
from django.template.defaultfilters import stringfilter
from django.utils.encoding import force_text
from django.utils.safestring import mark_safe
register = template.Library() #自定义filter时必须加上
@register.filter(is_safe=True) #注册template filter
@stringfilter #希望字符串作为参数
def custom_markdown(value):
return mark_safe(markdown.markdown(value,
extensions = ['markdown.extensions.fenced_code', 'markdown.extensions.codehilite'],
safe_mode=False,
enable_attributes=False))
感谢大家的帮助