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 后台修改文章,增加一段代码;然后进入文章详情页面,查看代码是否高亮
代码用反单引号引起(英文状态)