原帖:
https://code.ziqiangxuetang.com/django/django-cms-develop2.html
第一步,安装 DjangoUeditor 包
Python 3 开发者:https://github.com/twz915/DjangoUeditor3 直接下载zip(Python 2/3)
把里面的 DjangoUeditor-master 中的 DjangoUeditor 文件夹放到 该项目同一级目录,
在 minicms/settings.py 中加入 DjangoUeditor 这个应用
INSTALLED_APPS = ( ... 'news', 'DjangoUeditor', )
在 minicms/urls.py 中添加一行:
url(r'^ueditor/', include('DjangoUeditor.urls' )),
先引入,再使用:
from django.conf.urls import include, url from django.contrib import admin from DjangoUeditor import urls as DjangoUeditor_urls urlpatterns = [ url(r'^admin/', include(admin.site.urls)), url(r'^ueditor/', include(DjangoUeditor_urls)), ]
在 minicms/settings.py 设置 static 和 media
# Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/1.8/howto/static-files/ STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, 'static') # 公共的 static 文件,比如 jquery.js 可以放这里,这里面的文件夹不能包含 STATIC_ROOT STATICFILES_DIRS = ( os.path.join(BASE_DIR, "common_static"), ) # upload folder MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
在 minicms/urls.py 最后加入以下代码:
# use Django server /media/ files from django.conf import settings if settings.DEBUG: from django.conf.urls.static import static urlpatterns += static( settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
安装配置好后,修改 models.py
# 引入这个 Field,其它的不要变 from DjangoUeditor.models import UEditorField class Article(models.Model): ...省略 #仅修改 content 字段 content = UEditorField('内容', height=300, width=1000, default=u'', blank=True, imagePath="uploads/images/", toolbars='besttome', filePath='uploads/files/') ...