1 修改detail視圖函數,渲染文件的時候,增加codehight拓展
post.body = markdown.markdown(post.body, extensions=[ 'markdown.extensions.extra', 'markdown.extensions.codehilite', 'markdown.extensions.toc', ])
2 安裝Pygments 進入虛擬環境, pip install Pygments
3 修改base.html, 增加代碼高亮的樣式css 增加一行: <link rel="stylesheet" href="{% static 'blog/css/highlights/github.css %}"
templates/base.html ... <link rel="stylesheet" href="{% static 'blog/css/pace.css' %}"> <link rel="stylesheet" href="{% static 'blog/css/custom.css' %}"> ... + <link rel="stylesheet" href="{% static 'blog/css/highlights/github.css' %}">
4 后台修改文章,增加一段代碼;然后進入文章詳情頁面,查看代碼是否高亮
代碼用反單引號引起(英文狀態)
