简体   繁体   中英

Django-summernote customize

I'd like to customize django-summernote. Mostly by adding a few custom buttons. I can't figure out how to go about doing this.

I can see the documentation for adding custom buttons here:

http://summernote.org/deep-dive/#custom-button

But can't figure out where to add the javascript. I have added a custom file through my urls:

class CustomAdmin(admin.ModelAdmin):
class Media:
    js = (
         'js/summernote.js',       # project static folder
        )

class SectionParagraphAdmin(SummernoteModelAdmin, CustomAdmin):
search_fields = ('text',)

However, I don't seem to have access to summernote, like the docs are accessing it.

$('.summernote').summernote()

Returns undefined

Is it possible to customize django-summernote beyond the setting provided here: https://github.com/summernote/django-summernote#options

I made it but it might be a bad solution:

first,I went to my_venv/.../django_summernote/templates/djnago_summernote folder and overrided widget_iframe_editor.html file. I added just one declaration in head section:

  <head>
    ...
    <script src="{{ url }}"></script>{% endfor %}
    <script type="text/javascript" src="{% static "django_summernote/MySummernote.js" %}"></script> <!-- your js file-->
    </head>

then, I pasted my script in django_summernote/static/django_summernote folder.

For testing purpose I chose this js file .And It worked for me.Ofc dont forget to declare your new button in settings.py

'toolbar': [
    ....
    ['insert', ['link', 'picture', 'video', 'hr', 'readmore']],
    ['mybutton', ['hello']],
    ...
],

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM