DjangoUeditor富文本

不管是做项目管理系统,还是做网站,富本文是必用的,这里讲的是py2+django1.11,因为版本很重要。

1,安装富文本库:pip install DjangoUeditor

2,在项目的urls中添加:

url(r'^ueditor/', include('DjangoUeditor.urls')),

url(r'^$', views.index),

如果报include问题,就导入include:from django.conf.urls import url, include

如果报patterns问题, 就到DjangoUeditor目录下面urls.py中的patterns去除掉,换url,如下:

#coding:utf-8

from django import VERSION

if VERSION[0:2]>(1,3):

    from django.conf.urls import url

else:

    from django.conf.urls.defaults import url

from views import get_ueditor_controller

urlpatterns = [

url(r'^controller/$',get_ueditor_controller)

]

3,在项目的settings中加入项目DjangoUeditor:

INSTALLED_APPS = [

    'django.contrib.admin',

    'django.contrib.auth',

    'django.contrib.contenttypes',

    'django.contrib.sessions',

    'django.contrib.messages',

    'django.contrib.staticfiles',

    'web',

    'DjangoUeditor',

]

并在文件最后添加:

MEDIA_URL = '/static/uepload/'

MEDIA_ROOT = os.path.join(BASE_DIR, 'static/uepload')

4,定义models:

from DjangoUeditor.models import UEditorField

# 文章内容

class ArticleContent(models.Model):

    chapter_id = models.CharField('章节id', max_length=10)

    chapter_content = UEditorField(verbose_name=u'章节内容', default='')

5,添加到后台

import models

# 文章内容

class ArticleContentAdmin(admin.ModelAdmin):

    list_display = ('chapter_id', 'chapter_content')

    search_fields = ('chapter_content',)

admin.site.register(models.ArticleContent, ArticleContentAdmin)

到后台看效果如下:

6,在views中添加获取数据

def index(request):

# 获取文章内容

chapter_id = request.Get.get('id')

content_contacts = ArticleContent.objects.filter(id=chapter_id)

return render(request, 'index.html', { 'content_contacts': content_contacts})

7,前端页面显示富文本内容

{# 显示章节下的文章 #}

{% autoescape off %}

{% if content_contacts.count > 0 %}

{% for article_content in content_contacts %}

{{ article_content.chapter_content }}

{% endfor %}

{% endif %}

{% endautoescape %}

如果ueditor.html,ueditor_old.html显示无法加载,将Python27\Lib\site-packages\DjangoUeditor\templates目录下两个文件拷贝到项目 templates 目录

  • 7
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
DjangoUeditorUeditor封装为一个Django app,提供文件/图片等上传功能,提供UEditorField、UEditorWidget等封装类,简化UeditorDjango中的应用。注:Django是Python世界影响最大的Web框架。 本模块帮助在Django应用中集成百度Ueditor HTML编辑器,Django是Python世界最有影响力的web框架。 Ueditor HTML编辑器是百度开源的在线HTML编辑器,功能非常强大,像表格可以直接拖动调整单元格大小等。 更新历史 [2014-7-8] Ver:1.8.143 Fix:当admin使用inlines生成多实例时widget命名不正确的问题 [2014-6-27] Ver:1.7.143 Fix:解决在admin管理后台的使用问题。 增加year,month,day的上传路径变量 [2014-6-25] 由于Ueditor从1.4版本开始,API发生了非常大的改动和不兼容,导致DjangoUeditor上一个版本的升级后上传功能不能用等,因此 本次重新设计了API,后端上传的代码几乎完全重写了。 更新到1.5.143,即版本号为1.5,使用了Ueditor 1.4.3版本。 重新设计了UeditorWidget、UeditorField。 新增了自定义Ueditor按钮的功能 注意:本次升级与之前版本不兼容,但是在使用体验上差别不大。 [2014-6-16] 更新到Ueditor 1.4.3 [2014-5-15] 增加不过滤 script,style ,不自动转div为p的脚本 修复在django 1.6和python2.7下的警告 使用 json 代替 django 中的 simplejson 用content_type 代替原来的 mime_type [2014-5-7] 更新到Ueditor 1.3.6 BUGfix:更新UEditor文件夹名字,避免在linux出现找不到静态文件问题 添加一种样式,besttome, 希望大家喜欢 [2013-2-22] 更新到Ueditor 1.2.5 BUGfix:更新UEditor文件夹名字,避免在linux出现找不到静态文件问题 BUGfix:现在支持south更新了 针对csrf导致上传图片失败的问题,现在默认上传视图开启了csrf_exempt装饰 相关阅读 百度编辑器UEditor插件DjangoUeditor使用方法
### 回答1: 这个错误通常是因为你的项目没有安装 `DjangoUeditor` 模块导致的。你可以在命令行中运行以下命令来安装它: ``` pip install django-ueditor ``` 如果你已经安装了,那么可能是因为你没有将其添加到你的 `INSTALLED_APPS` 列表中。你可以在 `settings.py` 文件中找到这个列表,并添加 `'DjangoUeditor'` 到其中。这样应该可以解决这个错误。 ### 回答2: "ModuleNotFoundError: No module named 'DjangoUeditor'" 是一个Python错误消息,表示在你的项目中找不到名为 'DjangoUeditor' 的模块。 这个错误通常是由于缺少 'DjangoUeditor' 这个第三方库所导致的。要解决这个问题,首先要确保在你的项目中已经正确安装了 'DjangoUeditor'。可以使用命令行工具运行以下命令来安装: ``` pip install DjangoUeditor ``` 如果你已经安装了 'DjangoUeditor',同时仍然出现这个错误,可能是因为该模块的导入语句不正确。请确保你在你的代码中正确导入 'DjangoUeditor'。导入语句通常如下所示: ```python from DjangoUeditor import * ``` 实际导入语句可能与上述示例不同,具体取决于 'DjangoUeditor' 的包结构和你在项目中的使用方式。 如果你仍然无法解决这个错误,可能需要检查 'DjangoUeditor' 的安装位置是否正确,或者查看是否存在多个 Python 环境,并在正确的环境中安装它。 总之,根据错误消息查找缺失模块的原因,并采取相应措施,通常可以解决这个错误。 ### 回答3: 这个错误是由于在代码中引用了一个名为'DjangoUeditor'的模块,但是系统中没有安装这个模块所导致的。解决这个问题的步骤如下: 1. 首先,确保你已经在系统中安装了DjangoUeditor模块。你可以在命令行中运行`pip install DjangoUeditor`来安装该模块。如果你使用的是虚拟环境,请确保你已经激活了该虚拟环境。 2. 如果你已经安装了DjangoUeditor模块,还是遇到了这个错误,那可能是因为在你的项目中没有添加DjangoUeditor模块的配置。 3. 确保在你的项目的settings.py文件中添加了DjangoUeditor模块的配置。你需要在INSTALLED_APPS中添加'DjangoUeditor'。 4. 如果你已经添加了配置但还是遇到了这个错误,那可能是因为你在代码中错误地引用了'DjangoUeditor'模块。你需要检查你的代码,确保正确地引用了该模块。 总结来说,要解决这个错误,你需要确保已经安装了DjangoUeditor模块,并且在你的项目配置中添加了该模块。同时,你还需要检查你的代码,确保正确地引用了该模块。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值