", DetailView.as_view()),
+ ```
+
+- 修改模板`detail.html`
+
+ 通过safe参数来声明当前是元素
+
+ ```python
+
+ {{ article.content|safe }}
+
+ ```
+
+- 修改视图
+
+ ```python
+ class DetailView(TemplateView):
+ template_name = "detail.html"
+
+ def get(self, request, *args, **kwargs):
+ article = Article.objects.get(url=request.path)
+ content = ""
+ for line in article.text.split("\n"):
+ content += line.strip(" ") if "```" in line else line
+ content += "\n"
+ article.content = markdown.markdown(content, extensions=[
+ 'markdown.extensions.extra', # 转换标题, 字体等
+ 'markdown.extensions.codehilite', # 添加高亮功能
+ 'markdown.extensions.toc', # 将表单渲染为html document类型
+ ])
+ context = {
+ "article": article,
+ }
+ return self.render_to_response(context)
+ ```
+
+# 第三方应用
+
+- 安装django-mdeditor
+
+ ```python
+ # md文档后台管理页面编译应用
+ pip install django-mdeditor
+ ```
+
+- 在`settings`当中添加应用
+
+ ```python
+ INSTALLED_APPS = [
+ 'mdeditor',
+ ...
+ ]
+ ```
+
+- 修改`model`中文章内容字段类型
+
+ ```python
+ from mdeditor.fields import MDTextField
+
+ text = MDTextField()
+ ```
+
+# 课后作业
+
+- 完成类目和标签设计
+- 完成详情页设计
+- 添加和使用第三方应用`django-mdeditor`
+