显然,**不要在模板中使用粗体字符串,您将很难尝试在模板中用适当的开始和结束标记替换这些标记,例如通过自定义过滤器。但是,您可以通过在视图中应用必要的 HTML 并将其标记为安全来将其设为粗体:# views.pyfrom django.utils.safestring import mark_safe# in your view# ...text = "replace some word"# add the appropriate html tagstext = text.replace('some', '<strong>some</strong>')# now you have to mark it as safe so the tags will be rendered as tagstext = mark_safe(text)# ...return render(reqest, template, {.., 'text': text, ...})现在你可以像模板中的普通变量一样使用它 {{ text }}