File Browser no grapelli: NameError: name 'site' is not defined

File Browser no grapelli: NameError: name 'site' is not defined

我正在关注 this tutorial 安装 django-tinymce4-lite。在教程的最后有安装 django-filebrowser-no-grappelli.

的指示

我使用 Django 2.1.1,但即使我已按照所有指示进行操作,在安装文件浏览器后仍显示此消息:

File "/var/www/html/dev/miosito/django/beautifulsite_v0.1.1/djangosite/djangosite/urls.py", line 25, in path('admin/filebrowser/', include(site.urls)), NameError: name 'site' is not defined

这里有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: No module named 'site.urls'; 'site' is not a package

尝试以下操作:(删除 include

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

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

当您遇到特定于包本身的错误时,请始终参考包的官方文档。 (在本例中是django-filebrowser, although the main repo seems to be at django-filebrowser-no-grappelli). Blog sometime gets outdated easily. For example the guide from your link does not specify what Django version they are using. (Looking from the way the tutorial was written include, it seems to be Django<1.9 (reference))。

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