Django Невозможно добавить WYSIWYG
Я пытаюсь реализовать WYSIWYG на своей странице по этой ссылке : https://www.geeksforgeeks.org/adding-wysiwyg-editor-to-django-project/. Сейчас я нахожусь в пункте 5, когда они хотят, чтобы я добавил ниже:
# add condition in django urls file
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)
но когда я добавил выше, я получил следующее сообщение об ошибке
File "C:\Download\Development\NowaStrona_Django\mysite\my_site\my_site\urls.py", line 6, in <module>
path('', include('blog.urls')),
File "C:\Download\Development\NowaStrona_Django\lib\site-packages\django\urls\conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "C:\Download\Development\NowaStrona_Django\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Download\Development\NowaStrona_Django\mysite\my_site\blog\urls.py", line 16, in <module>
urlpatterns += static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)
NameError: name 'static' is not defined
Я прилагаю urls.py:
from . import views
from django.urls import path
urlpatterns = [
path('', views.PostList.as_view(), name='home'),
path('<slug:slug>/', views.PostDetail.as_view(), name='post_detail'),
]
# to jest dla wysiwyg
# add condition in django urls file
from django.conf import settings
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)
Знаете ли вы, почему я получаю сообщение об ошибке?
Вам не хватает оператора импорта
from django.conf.urls.static import static
Вышеуказанная проблема была решена. Но когда я теперь захожу в админку и хочу добавить пост, я получаю следующее сообщение:
NoReverseMatch at /admin/blog/post/add/
Reverse for 'django_summernote-upload_attachment' not found. 'django_summernote-upload_attachment' is not a valid view function or pattern name.
Request Method: GET
Request URL: http://127.0.0.1:8080/admin/blog/post/add/
Django Version: 3.2.9
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'django_summernote-upload_attachment' not found. 'django_summernote-upload_attachment' is not a valid view function or pattern name.
Exception Location: C:\Download\Development\NowaStrona_Django\lib\site-packages\django\urls\resolvers.py, line 694, in _reverse_with_prefix
Python Executable: C:\Download\Development\NowaStrona_Django\Scripts\python.exe
Python Version: 3.7.3
Python Path:
['C:\\Download\\Development\\NowaStrona_Django\\mysite\\my_site',
'C:\\Download\\Development\\NowaStrona_Django\\Scripts\\python37.zip',
'C:\\Download\\Development\\NowaStrona_Django\\DLLs',
'C:\\Download\\Development\\NowaStrona_Django\\lib',
'C:\\Download\\Development\\NowaStrona_Django\\Scripts',
'c:\\program files (x86)\\python37-32\\Lib',
'c:\\program files (x86)\\python37-32\\DLLs',
'C:\\Download\\Development\\NowaStrona_Django',
'C:\\Download\\Development\\NowaStrona_Django\\lib\\site-packages']
Server time: Tue, 21 Dec 2021 17:36:13 +0000
Error during template rendering
In template C:\Download\Development\NowaStrona_Django\lib\site-packages\django\contrib\admin\templates\admin\includes\fieldset.html, error at line 19
Reverse for 'django_summernote-upload_attachment' not found. 'django_summernote-upload_attachment' is not a valid view function or pattern name.
9 {% for field in line %}
10 <div{% if not line.fields|length_is:'1' %} class="fieldBox{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% if not field.is_readonly and field.errors %} errors{% endif %}{% if field.field.is_hidden %} hidden{% endif %}"{% elif field.is_checkbox %} class="checkbox-row"{% endif %}>
11 {% if not line.fields|length_is:'1' and not field.is_readonly %}{{ field.errors }}{% endif %}
12 {% if field.is_checkbox %}
13 {{ field.field }}{{ field.label_tag }}
14 {% else %}
15 {{ field.label_tag }}
16 {% if field.is_readonly %}
17 <div class="readonly">{{ field.contents }}</div>
18 {% else %}
19 {{ field.field }}
20 {% endif %}
21 {% endif %}
22 {% if field.field.help_text %}
23 <div class="help">{{ field.field.help_text|safe }}</div>
24 {% endif %}
25 </div>
26 {% endfor %}
27 </div>
28 {% endfor %}
29 </fieldset>
Знаете ли вы, что может стать проблемой?