helloflask / flask-ckeditor

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

custom config not working #14

Closed git-bone closed 5 years ago

git-bone commented 5 years ago

Hi,

I'm using Flask-CKeditor currently with Flask-Admin in standard view and trying to set configuration in config.py to get it to basic. Why isn't this working? simplified code is as follows. This code works fine but continues to show only the standard ckeditor. I would like it to be the basic view, as is set in the config.py file.

init.py:

cdeditor = CKEditor()
def create_app(config_class = Config):    
    app = Flask(__name__)    
    app.config.from_object(config_class)    
    ckeditor = CKEditor(app)

config.py: class Config(object): CKEDITOR_PKG_TYE = 'basic'

Flask-Admin view: form_overrides = { 'fieldname': CKEditorField }

my_create.html: {% extends 'admin/model/create.html' %} {% block tail %} {{ super() }} {{ ckeditor.load() }} {% endblock %}>

greyli commented 5 years ago

There is a typo in your code: CKEDITOR_PKG_TYE should be CKEDITOR_PKG_TYPE.

git-bone commented 5 years ago

yeah, you're right. Well, that is just a typo here, in the actual file it is written correctly.

greyli commented 5 years ago

Please try to update your init.py to this:

ckeditor = CKEditor()

def create_app(config_class = Config):    
    app = Flask(__name__)    
    app.config.from_object(config_class)    
    ckeditor.init_app(app)  # <-- notice this line

...
git-bone commented 5 years ago

That gives a NameError 'ckeditor' is not defined.

greyli commented 5 years ago

Could you provide the full traceback for the NameError exception?

git-bone commented 5 years ago

That would be this. In the meantime, may I thank you for the very fast response to my issue :)

Traceback (most recent call last): File "run.py", line 9, in app = create_app() File "/home/user/app/_init.py", line 26, in create_app ckeditor.init_app(app) NameError: name 'ckeditor' is not defined

git-bone commented 5 years ago

wait a minute. I made a type elsewhere... app is running now, but still, not in basic mode.

greyli commented 5 years ago

You are welcome :p Yeah, I notice you typo the ckeditor to cdeditor...

git-bone commented 5 years ago

But how to get it to basic mode? the ckeditor field is still default 'standard'...

greyli commented 5 years ago

Please add this line under ckeditor.load() in your template:

{{ ckeditor.config() }}
greyli commented 5 years ago

You also need to pass the name parameter, the value should be the name of CKEditor form field:

{{ ckeditor.config(name='Your CKEditor form field name') }}
git-bone commented 5 years ago

Tried both, with and without field name, but unfortunately still standard view. Am I missing something here?

greyli commented 5 years ago

Are you sure you pass the correct name value? Also, please provide the rendered HTML source for the page.

git-bone commented 5 years ago

well, finally found the issue. Your hint on html source put me on the right track. There was an old link to ckeditor script still in the base html. Removed that, and now it works. thanks anyway, and keep on the good work :)

greyli commented 5 years ago

:)

git-bone commented 5 years ago

btw, in the template this part is not needed. loading is sufficient to get it working;

{{ ckeditor.config() }}

greyli commented 5 years ago

You are right, I just found this part in docs:

Except CKEDITOR_SERVE_LOCAL and CKEDITOR_PKG_TYPE, when you use other configuration variable, you have to call ckeditor.config() in template to make them register with CKEditor:

<body>
...  <!-- {{ ckeditor.load() }} or <script src="/path/to/ckeditor.js"> -->
{{ ckeditor.config() }}
</body>
git-bone commented 5 years ago

yep, that's what I saw and tested it here. Again, many thanks for your fast response.