下载python下的markdown解析器.
$sudo pip install markdown
或者是
$sudo easy install markdown
其他安装方式可参考markdown的python解析器
在app的models.py中创建一个博文的类Post
[python] view plain copy print?
class Category(models.Model):
name = models.CharField(max_length=20)
def __unicode__(self):
return self.name
class Post(models.Model):
category = models.ForeignKey(Category)
title = models.CharField(max_length=60)
body = models.TextField()
date = models.DateTimeField(auto_now_add=True)
def __unicode__(self):
return self.title
在view中使用markdown
导入包
[python] view plain copy print?
from markdown import markdown
解析post.body
[python] view plain copy print?
for post in posts:
post.body = markdown(post.body)
后台编辑博文
添加如下内容
> ## This is a header.
>
> 1. This is the first list item.
> 2. This is the second list item.
>
> Here's some example code:
>
> return shell_exec("echo $input | $markdown_script");
前端显示效果