找回密碼
 註冊
搜索
查看: 2333|回復: 0

[教學] Flask render_template 如何崁入Ckeditor 編輯器

[複製鏈接]
發表於 2025-7-31 18:28:21 | 顯示全部樓層 |閱讀模式
Push to Facebook
1. 安裝

  1. pip install flask-ckeditor
複製代碼

先安裝flask_ckeditor套件。在主程式中需要先建立Flask實體,再使用Ckeditor應用在Flask實體中。
如果你也需要使用code block,只要在configure中設定CKEDITOR_ENABLE_CODESNIPPET = True,就可以在Ckeditor的網頁編輯器中找到code editor的icon。

2.初始化 xxx.py

  1. from flask import Flask
  2. from flask_ckeditor import CKEditor

  3. app = Flask(__name__)
  4. ckeditor = CKEditor(app)

  5. # set SECRET_KEY=mysecret
  6. app.config['SECRET_KEY'] = 'mysecret'
  7. # Configure CKEditor to include the Code Snippet plugin
  8. app.config['extraPlugins'] = 'codesnippet'
  9. app.config['CKEDITOR_ENABLE_CODESNIPPET'] = True
複製代碼
也可加到__init__.py裡

3. template 模板檔案 如 index.html
  1. <body>
  2.     ...
  3.     <textarea class="ckeditor" cols="40" id="editor1" name="content" rows="10">{{company.content}}</textarea>
  4.     {{ ckeditor.load() }}
  5. </body>
複製代碼

展示畫面:

Flask render_template 崁入 Ckeditor 編輯器

Flask render_template  崁入 Ckeditor 編輯器



這時出現 "CKEditor 4.22.1 version is not secure"的提示訊息
在該模板html下加入代碼,即可關閉此訊息

  1. <style>
  2.     .cke_notifications_area  { display: none; }
  3. </style>
複製代碼

Flask render_template 崁入 Ckeditor 編輯器

Flask render_template  崁入 Ckeditor 編輯器



如果要讀取自用的ckeditor.js

html下加入代碼
  1. {{ ckeditor.load(custom_url=url_for('static', filename='ckeditor/ckeditor.js')) }}
複製代碼


圖片上傳部分待解


文章來源:NetYea 網頁設計

參考文章
https://flask-ckeditor.readthedo ... c.html#installation
https://freepythonsourcecode.com/post/78

https://www.danpoints.com/blog/15
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

Archiver|手機版|小黑屋|TShopping

GMT+8, 2025-9-14 09:45 , Processed in 0.024548 second(s), 22 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回復 返回頂部 返回列表