Reputation:
I am trying to get TinyMCE working in Django. Here is what I did:
pip install django-tinymce4-lite
; package installs fineThen here it gets tricky:
Add tinymce.urls to urls.py for your project:
urlpatterns = [
...
url(r'^tinymce/', include('tinymce.urls')),
...
]
When I do this, I get this error:
url(r'^tinymce/', include('tinymce.urls')),
NameError: name 'url' is not defined
I have tried the following:
None of this helped. Any suggestions?
UPDATE
As per the suggestions, I updated url to path. Now I have a new error:
ModuleNotFoundError: No module named 'tinymce.urls'
Here is my urls.py:
from django.urls import include, path
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('', include('core.urls')),
path('tinymce/', include('tinymce.urls')),
]
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
This error made me doubt if I had installed the plugin correctly. But it seems I have:
pip install django-tinymce4-lite
Requirement already satisfied: django-tinymce4-lite in /usr/local/lib/python3.6/site-packages
Requirement already satisfied: Django>=1.8.0 in /usr/local/lib/python3.6/site-packages (from django-tinymce4-lite)
Requirement already satisfied: jsmin in /usr/local/lib/python3.6/site-packages (from django-tinymce4-lite)
Requirement already satisfied: pytz in /usr/local/lib/python3.6/site-packages (from Django>=1.8.0->django-tinymce4-lite)
Upvotes: 1
Views: 5812
Reputation: 515
Error continues with Django==5.0.3; Python 3.11; django-tinymce4-lite==1.8.0. The error message shows us the cause is on line 1 of /root/env/lib/python3.11/site-packages/tinymce/urls.py.
I changed the tinymce/urls as suggested by this Stackoverflow gives solutions. For example, a quick solution is:
### changed april 2024 to handle
### ImportError: cannot import name 'url' from 'django.conf.urls'
#from django.conf.urls import url
from django.urls import re_path as url
This is not a good long term solution. I plan to submit it tinymcs to see if it needs an update or find out if they have a better solution.
Upvotes: 0
Reputation: 281
is because he's using django 2 According to the documentation you can use path and re_path example :
from django.urls import path , re_path
urlpatterns = [
path('tinymce/', include('tinymce.urls')),
# or
#path('tinymce/', include('tinymce.urls')),
]
Upvotes: 0
Reputation: 47374
Since you are using django 2.0 you should use path
instead of url
:
from django.urls import path
urlpatterns = [
...
path('tinymce/', include('tinymce.urls')),
...
]
You can find more details here.
Upvotes: 1