lqez / django-summernote

Simply integrate Summernote editor with Django project.
MIT License
1.05k stars 227 forks source link

`NoReverseMatch` error when `disable_attachment` is set to `True` #464

Closed amrishparmar closed 9 months ago

amrishparmar commented 3 years ago

Python: 3.9.7 Django: 3.2.8 django-summernote: 0.8.20.0

In our SUMMERNOTE_CONFIG we have disable_attachment: True, however when attempting to load a page that includes a Summernote widget we get the following traceback:

File "/root/.local/lib/python3.9/site-packages/django_summernote/widgets.py", line 63, in render
     summernote_settings = self.summernote_settings()
File "/root/.local/lib/python3.9/site-packages/django_summernote/widgets.py", line 28, in summernote_settings
     'upload_attachment': reverse('django_summernote-upload_attachment'),
File "/root/.local/lib/python3.9/site-packages/django/urls/base.py", line 86, in reverse
     return resolver._reverse_with_prefix(view, prefix, *args, **kwargs)
File "/root/.local/lib/python3.9/site-packages/django/urls/resolvers.py", line 694, in _reverse_with_prefix
     raise NoReverseMatch(msg)
 django.urls.exceptions.NoReverseMatch: Reverse for 'django_summernote-upload_attachment' not found. 'django_summernote-upload_attachment' is not a valid view function or pattern name.

It looks like it's caused by SummernoteWidgetBase.summernote_settings on line 28 'upload_attachment': reverse('django_summernote-upload_attachment') where it attempts to get the URL irrespective of whether the attachment feature is disabled. Since the change in https://github.com/summernote/django-summernote/commit/073eaaa80c13ddcee5cda3fede7b65247db165b6 no longer includes the URLs when the feature is disabled, it's failing to find the view and causing the exception.

claudep commented 3 years ago

I'm affected by this issue, too.

quroom commented 2 years ago

I will make PR this is bug. Before fix it, remove disable_attachement: True code. And it will works. This is temporary solution. Without that, it need to be fixed in https://github.com/summernote/django-summernote/blob/8b17863d44ad1a588ea46d79203461275456e654/django_summernote/widgets.py#L28 This code has to be conditional by config.