【问题标题】:File Browser no grapelli: NameError: name 'site' is not defined文件浏览器没有gratelli:NameError:名称“站点”未定义
【发布时间】:2019-02-27 07:35:06
【问题描述】:

我正在关注 this tutorial 以安装 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 行,在 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:没有名为“site.urls”的模块; “网站”不是 包

【问题讨论】:

  • 你忘了from filebrowser.sites import site
  • 现在我又有一个错误
  • 您为什么不按照教程进行操作?改用这个path('admin/filebrowser/', include(site.urls)),
  • 如果你引用site.urls,那么它意味着不同的东西......
  • Yeo 我已经使用了 site.urls 上的报价,但出现了这个错误:

标签: django python-3.6 django-tinymce django-filebrowser django-2.1


【解决方案1】:

尝试以下操作:(删除include

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

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-26
    • 2016-08-24
    • 2020-10-16
    • 1970-01-01
    • 2012-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多