Issue
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?
Solution
You're missing an import statement
from django.conf.urls.static import static
Answered By - Hack_Hut
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.