from pygments.lexers import get_lexer_by_name
from pygments.formatters.html import HtmlFormatter
from pygments import highlight
再为Snippets模型自定义save方法
defsave(self,*args,**kwargs):"""
Use the `pygments` library to create a highlighted HTML
representation of the code snippet.
"""
lexer = get_lexer_by_name(self.language)
linenos ='table'if self.linenos elseFalse
options ={
'title': self.title