基于django快速开发一个网站(三)
给django集成富文本编辑器
下载富文本插件到系统
pip install django-mdeditor1
添加mdeditor到你的应用中
INSTALLED_APPS = [ … 'mdeditor', ]1234
配置media到settings.py中
MEDIA_ROOT = os.path.join(BASE_DIR, 'uploads')MEDIA_URL = '/media/'12
配置路由
from django.conf.urls import url, includefrom django.conf.urls.static import staticfrom django.conf import settingsurlpatterns = [ url(r'mdeditor/', include('mdeditor.urls'))]if settings.DEBUG: # static files (images, css, javascript, etc.) urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)1234567891011
配置models层
from django.db import modelsfrom mdeditor.fields import MDTextFieldclass ExampleModel(models.Model): name = models.CharField(max_length=10) content = MDTextField()123456
6.运行迁移命令、使models层的数据生效
python3 manage.py makemigrations python3 manage.py migrate12
赞 (0)