1

我正在按照本教程安装django-tinymce4-lite。在教程的最后有安装django-filebrowser-no-grappelli 的指示

我使用 Django 2.1.1,但即使我已遵循所有指示,在安装文件浏览器后仍显示此消息:

文件“/var/www/html/dev/miosito/django/beautifulsite_v0.1.1/djangosite/djangosite/urls.py”,第 25 行,在路径('admin/filebrowser/',include(site.urls))中,NameError :名称“站点”未定义

这里有 urls.py:

from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
from filebrowser.sites import site #sorry I've forgot this

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('testapp.urls')), #app for my tests
    path('tinymce/', include('tinymce.urls')),
    path('admin/filebrowser/', include('site.urls')),
]

if settings.DEBUG:
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

我做错了什么?

Yeo校正后编辑:

我已经添加了我忘记的字符串并且我已经正确了

path('admin/filebrowser/', include(site.urls)), 

path('admin/filebrowser/', include('site.urls')),

但现在我有这个新错误:

ModuleNotFoundError:没有名为“site.urls”的模块;“网站”不是一个包

4

1 回答 1

2

请尝试以下操作:(删除include

# ...
from filebrowser.sites import site
# ...

urlpatterns = [
    # ...
    path('admin/filebrowser/', site.urls),
    # ...
]

当您遇到特定于包本身的错误时,请始终参考包官方文档。(在这种情况下是django-filebrowser,虽然主仓库似乎在django-filebrowser-no-grappelli)。博客有时很容易过时。例如,您链接中的指南未指定他们使用的 Django 版本。(从教程的写法include来看,好像是 Django<1.9 (reference))。

如果你使用的是 Django>=2,那么官方文档应该解释了安装这个包的正确方法。

于 2018-09-23T18:54:12.223 回答