7.django之markdown

安装库:pip install markdown
导入库:import markdown

在视图函数中使用:

def page_detail(request, category_name_slug, page_id):
    category = Category.objects.get(course=category_name_slug)
    page = category.page_set.get(id = page_id)
    page.content = markdown.markdown(page.content)
    context = {
        'page':page
    }
    return render(request, 'mamengli_blog/page_detail.html', context)

你可能感兴趣的:(7.django之markdown)