Django admin后台使用markdown
作者:互联网
场景
django admin后台,发布内容实用markdown格式
插件
pip install django-mdeditor
在setting app下注册
设置markdown上传图片路径,在setting.py中
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
# 顺便配置下静态资源的根目录
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
# settings.py中配置该值
X_FRAME_OPTIONS = 'SAMEORIGIN'
配置路由
from django.urls import path,include,re_path
from django.views.static import serve
from speakMovie.settings import STATIC_ROOT, MEDIA_ROOT
path(r'mdeditor/', include('mdeditor.urls')),
# django关闭debug模式后,静态文件无法访问,这里要设置下静态文件的访问路由
re_path(r'^static/(?P<path>.*)$', serve, {'document_root': STATIC_ROOT}),
re_path(r'^media/(?P<path>.*)', serve, {"document_root": MEDIA_ROOT}),
关闭debug模式后,要使用命令把下载的第三方APP静态文件拷贝一份到static路径下
python manage.py collectstatic
model数据
contents = MDTextField()
这样就完成了,可以去后台添加查看,就OK了
标签:markdown,admin,MEDIA,django,static,path,Django,ROOT 来源: https://www.cnblogs.com/TestingShare/p/16364568.html