helloflask / flask-ckeditor

CKEditor integration for Flask, including image upload, code syntax highlight, and more.
https://flask-ckeditor.readthedocs.io
MIT License
200 stars 67 forks source link

CKEditor upload tab doesn't appear #18

Closed Kevinf7 closed 4 years ago

Kevinf7 commented 5 years ago

Hi,

I have tried everything but I can't seem to get the file upload tab to appear in the CKeditor (in Image Properties).

It is strange because it was working for me a few months ago with the same code and I successfully uploaded images. I don't know if anything has changed since then. The code below is what I used and it is pretty much the same as the one in the documentation. My Flask CKEditor version is 4.9.2

Would you know if there is any known issue? Thanks.

In config.py

CKEDITOR_HEIGHT=250
CKEDITOR_WIDTH='100%'
CKEDITOR_PKG_TYPE='standard'
CKEDITOR_SERVE_LOCAL=True
CKEDITOR_FILE_UPLOADER='upload'
basedir = os.path.abspath(os.path.dirname(__file__))
UPLOADED_PATH=os.path.join(basedir, 'uploads')
CKEDITOR_UPLOAD_ERROR_MESSAGE='Upload failed'

In __init__.py

from flask_ckeditor import CKEditor
ckeditor = CKEditor(app)

In route.py

@app.route('/files/<filename>')
def uploaded_files(filename):
path = app.config['UPLOADED_PATH']
return send_from_directory(path, filename)

@app.route('/upload', methods=['POST'])
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!')
f.save(os.path.join(app.config['UPLOADED_PATH'], f.filename))
url = url_for('uploaded_files', filename=f.filename)
return upload_success(url=url)
NamelessAshone commented 5 years ago

@Kevinf7 Hi,

I meet this problem too.

Maybe you can try {{ ckeditor.load() }} to load ckeditor.js. And using {{ ckeditor.config() }} to load
your custom config.I solved this problem in this way.

I am sorry for my poor english

greyli commented 4 years ago

Yes, {{ ckeditor.config() }} is required when you set any CKEDITOR_FOO config. Also, remember to pass the field name when you use Flask-WTF or Flask-Admin:

{{ ckeditor.config(name='form_field_name') }}