Django 部落格的富文字

2021-08-25 17:02:08 字數 2002 閱讀 6316

最開始使用的富文字tinymice沒有**高亮, 而且簡單

後有再試了其他幾種, 最後選擇了ueditor

##1、安裝方法

python setup.py install

pip install djangoueditor

##4、在models中的使用

from djangoueditor.models import ueditorfield

class blog(models.model):

name=models.charfield(,max_length=100,blank=true)

content=ueditorfield(u'內容 ',width=600, height=300, *******s="full", imagepath="", filepath="", upload_settings=,settings={},command=none,event_handler=myeventhander(),blank=true)

from widgets import ueditorwidget,adminueditorwidget 

importerror: no module named 『widgets』

djangoueditor相容python3的版本github:   

最後結果如下:

在django的settings.py裡加配置

ueditor_settings = ,

"images_upload":,

"files_upload":,

"image_manager":

}

注意:

class blog(models.model):

title = models.charfield("標題", max_length=30)

img = models.imagefield("", upload_to='img', default="")

author = models.charfield("作者", max_length=30)

publish_time = models.datetimefield('發布日期', default=timezone.now)

content = ueditorfield(u'內容', width=900, height=600, *******s="full", imagepath="uploadimg/", filepath="files",

upload_settings=, settings={}, command=none, blank=true)

is_casual = models.booleanfield("隨筆", default=false)

tags = models.manytomanyfield(tags, verbose_name="標籤")

模型裡面的ueditorfield欄位中的imagepath="uploadimg/" 一定腰帶/

否則如下:

**高亮:

在html內容如下:

小魚兒的

}

}   是django的templates模板渲染的, content為model中的富文字字段。

頁面顯示:

django 筆記 富文字使用

第二步 註冊 配置富文字功能 配置 ckeditor ckeditor upload path upload ckeditor configs comment ckeditor 配置上傳路徑 media media url media media root os.path.join base dir...

django中使用tinymce 富文字

安裝完成之後,就可以在d python lib site packages django tinymce 2.7.0 py3.6.egg這個資料夾。點選進入資料夾,copy tinymce 這個檔案到你的專案的根目錄下。pip install django tinymce 在settings.py加...

django 後台從富文字提取純文字

很多時候我們都會用富文字,比如說在版權區 部落格文章編輯時等等。但是如果我們要做乙個搜尋的功能,去從富文字中查詢關鍵字,就需要將富文字中的文字了。但是 django 並沒有專門函式去做。這個時候我們就需要使用正則或者是提取前端的過濾器 striptags 方法。import re content j...