django整合ueditor富文本编辑器并解决图片视频等无法上传显示问题

         一般django后台的文本编辑器比较简单,所以增加ueditor编辑器。
        ueditor编辑是百度开发开源产品,官网没django版本。
        django版本下载地址   https://github.com/zhangfisher/DjangoUeditor/archive/master.zip 
         解压后将 DjangoUeditor  文件夹复制到django项目目录下,跟app目录同级

        开始修改 :
                url.py文件  
                     
                      导入              from  DjangoUeditor  import  urls as  DjangoUeditor_urls                   
                     增加路由        url(r'^ueditor/', include(DjangoUeditor_urls)) 
             
             models  文件  
                       导入        from DjangoUeditor.models  import   UEditorField
                      对于需要使用编辑器的子段定义

                    context = UEditorField( '内容' , height = 300 , width = 1000 , default
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Python Django富文本编辑器可以通过使用第三方库和插件来实现上传功能。常用的方法是使用django-ckeditor库或django-tinymce库来集成富文本编辑器以及上传功能。 首先,在Django项目中安装所需的库,可以通过在终端中运行以下命令安装库: ```python pip install django-ckeditor pip install django-tinymce ``` 安装完成后,需要在Django的设置文件中进行相应的配置。对于django-ckeditor库,需要将以下内容添加到settings.py中的INSTALLED_APPS和STATIC_URL中: ```python INSTALLED_APPS = [ ... 'ckeditor', ] STATIC_URL = '/static/' STATICFILES_DIRS = [ ... os.path.join(BASE_DIR, 'static') ] ``` 对于django-tinymce库,需要将以下内容添加到settings.py中的INSTALLED_APPS和STATIC_URL中: ```python INSTALLED_APPS = [ ... 'tinymce', ] STATIC_URL = '/static/' STATICFILES_DIRS = [ ... os.path.join(BASE_DIR, 'static') ] ``` 然后,需要在urls.py文件中添加相应的URL配置。对于django-ckeditor库,可以添加以下代码: ```python from django.contrib import admin from django.urls import include, path from django.conf import settings from django.conf.urls.static import static from ckeditor_uploader import views as ckeditor_views urlpatterns = [ ... path('ckeditor/', include('ckeditor_uploader.urls')), path('admin/', admin.site.urls), ] if settings.DEBUG: urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) ``` 对于django-tinymce库,可以添加以下代码: ```python from django.contrib import admin from django.urls import include, path from django.conf import settings from django.conf.urls.static import static from tinymce import views as tinymce_views urlpatterns = [ ... path('tinymce/', include('tinymce.urls')), path('admin/', admin.site.urls), ] if settings.DEBUG: urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) ``` 最后,还需要进行一些前端和后端的配置。具体可以参考文档或库的使用说明来实现上传功能。 以上就是使用Python Django富文本编辑器实现上传功能的简要步骤。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值