pip install -i https://pypi.tuna.tsinghua.edu.cn/simple django-mdeditor
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'mdeditor'
]
MEDIA_ROOT = os.path.join(BASE_DIR, '[yourapp]/../uploads')
MEDIA_URL = '/[yourapp]/media/'
文件路径如下:
[yourapp]
__init__.py
settings.py
urls.py
wsgi.py
uploads
editor
from django.views.static import serve
from [yourapp].settings import MEDIA_ROOT
urlpatterns = [
path('media/<path:path>', serve, {'document_root':MEDIA_ROOT}),
]
from mdeditor.fields import MDTextField
# 文档列表
class DocumentList(models.Model):
# 文档ID
id = models.AutoField(primary_key=True, verbose_name='文档ID')
# 名称
title = models.CharField(max_length=50, verbose_name='名称')
# 发布时间
time = models.DateTimeField(auto_now=True, verbose_name='发布时间')
# 文档内容
content = MDTextField(null=True)