I am trying to implement WYSIWYG on my page with this link : https://www.geeksforgeeks.org/adding-wysiwyg-editor-to-django-project/ I am currently at point 5, when they want me to add below:
# add condition in django urls file
if settings.DEBUG:
urlpatterns = static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)
but when I added above, I got below error message
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
I am attaching 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)
Do you know why I am getting pasted error message?
CodePudding user response:
You're missing an import statement
from django.conf.urls.static import static
CodePudding user response:
Above issue was solved. Although when I go now to admin and want to add post, I get this message:
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' %} {% elif field.is_checkbox %} {% 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 >{{ field.contents }}</div>
18 {% else %}
19 {{ field.field }}
20 {% endif %}
21 {% endif %}
22 {% if field.field.help_text %}
23 <div >{{ field.field.help_text|safe }}</div>
24 {% endif %}
25 </div>
26 {% endfor %}
27 </div>
28 {% endfor %}
29 </fieldset>
Do you know what can be an issue?