2012-01-25 50 views
0

我周圍搜索,似乎沒有任何好的解決方案。在Django html頁面顯示synatx突出顯示的源代碼

最接近的一個:django-pygments不支持模板上下文/變量作爲語言選項傳遞。

我想知道是否有人知道支持snippet類型的好解決方案作爲模板上下文傳遞?

謝謝。

+1

怎麼樣JavaScript解決方案,如[SHJS(http://shjs.sourceforge.net/)? –

+0

@JoachimPileborg謝謝。我要看看這個。我嘗試了highlight.js,我不知道爲什麼它不起作用。 – CppLearner

回答

1

模板:

{% content|pygmentize:lang %} 

查看:

def show(request): 
    ctx = dict() 
    ctx['content'] = 'alert("hello");' 
    ctx['lang'] = 'javascript' 
    return render(request,'template.html',ctx) 
+0

嗨。謝謝。這是django-pygments的解決方案嗎?或者只要求我使用python的pygement。 – CppLearner

+0

這是與Django-pygments。 –