我想让TinyMCE在Django中工作。这是我做的:
pip install django-tinymce4-lite
;包安装正常然后在这里变得棘手:
Add tinymce.urls to urls.py for your project:
urlpatterns = [
...
url(r'^tinymce/', include('tinymce.urls')),
...
]
当我这样做时,我收到此错误:
url(r'^tinymce/', include('tinymce.urls')),
NameError: name 'url' is not defined
我尝试了以下内容:
这些都没有帮助。有什么建议?
更新
根据建议,我将url更新为路径。现在我有一个新错误:
ModuleNotFoundError: No module named 'tinymce.urls'
这是我的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)
这个错误让我怀疑我是否正确安装了该插件。但似乎我有:
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)
答案 0 :(得分:1)
由于您使用的是django 2.0,因此应使用path
代替url
:
from django.urls import path
urlpatterns = [
...
path('tinymce/', include('tinymce.urls')),
...
]
您可以找到更多详情here。
答案 1 :(得分:0)
您有NameError,因为您在url
中引用urls.py
但尚未导入它。将以下行添加到urls.py
from django.conf.urls import url
答案 2 :(得分:0)
是因为他正在使用django 2 根据您可以使用的documentation path and re_path示例:
from django.urls import path , re_path
urlpatterns = [
path('tinymce/', include('tinymce.urls')),
# or
#path('tinymce/', include('tinymce.urls')),
]