[英]Flask Admin Ckeditor Image Upload
For Flask Admin How is it possible to upload images in Text area with editor ? 对于Flask Admin,如何使用编辑器在“文本”区域中上传图像?
I need simpler version than this: 我需要比这更简单的版本:
https://github.com/greyli/flask-ckeditor https://github.com/greyli/flask-ckeditor
from flask_ckeditor import *
csrf = CSRFProtect(app)
csrf.init_app(app)
ckeditor = CKEditor(app)
app.config['CKEDITOR_SERVE_LOCAL'] = False
app.config['CKEDITOR_HEIGHT'] = 400
app.config['CKEDITOR_FILE_UPLOADER'] = 'upload'
app.config['UPLOADED_PATH'] = os.path.join(basedir, 'uploads')
@app.route('/files/<filename>')
@csrf.exempt
def uploaded_files(filename):
path = app.config['UPLOADED_PATH']
return send_from_directory(path, filename)
import uuid
@app.route('/upload', methods=['POST'])
@csrf.exempt
def upload():
f = request.files.get('upload')
extension = f.filename.split('.')[1].lower()
if extension not in ['jpg', 'gif', 'png', 'jpeg']:
return upload_fail(message='Image only!')
unique_filename = str(uuid.uuid4())
f.filename = unique_filename + '.' + extension
f.save(os.path.join(app.config['UPLOADED_PATH'], f.filename))
url = url_for('uploaded_files', filename=f.filename)
return upload_success(url=url)
in edit.html in flask admin 在flask admin中的edit.html中
<script>
CKEDITOR.plugins.addExternal( 'filebrowser', '/static/ckeditor/filebrowser/', 'plugin.js' );
CKEDITOR.config.extraPlugins = 'filebrowser';
CKEDITOR.config.filebrowserBrowseUrl = '/upload';
<script>
This works for flask admin to upload images 这适用于烧瓶管理员上传图像
https://github.com/greyli/flask-ckeditor I used this https://github.com/greyli/flask-ckeditor我用了这个
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.