[python] Django换用Markdown编辑器

2020-03-15  本文已影响0人  丶噗噗噗噗噗

Django换用Markdown编辑器

参考:

安装所需包

pip install django-mdeditor

报错 UnicodeDecodeError: 'gbk' codec can't decode byte 0xad in position 167: illegal multibyte sequence
最新版本中有冲突
换用 pip install django-mdeditor==0.1.16

pip install markdown

Django配置

配置settings.py

INSTALLED_APPS = [
        ...
        'mdeditor',
    ]
MEDIA_ROOT = os.path.join(BASE_DIR, 'uploads')
MEDIA_URL = '/media/'

配置urls.py

urlpatterns = [
    ...
    path('mdeditor'), include('mdeditor.urls'), 
]

修改models

from mdeditor import MDTextField
...
content = MDTextField()

修改views

blog.content = markdown.markdown(blog.content)

执行数据库迁移

python manage.py makemigrations
python manage.py migrate

上一篇下一篇

猜你喜欢

热点阅读