Search code examples
djangopython-3.6django-tinymcedjango-filebrowserdjango-2.1

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


I'm following this tutorial for install django-tinymce4-lite. At the end of the tutorial there are the indications to install django-filebrowser-no-grappelli.

I use Django 2.1.1 but even though I've followed all the indications, after the installation of the file browser was shown this message:

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

Here there is 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)

What I've wrong?

EDIT after Yeo correction:

I've add the string that I've forgot and I've correct

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

with

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

but now I've this new error:

ModuleNotFoundError: No module named 'site.urls'; 'site' is not a package


Solution

  • Try the following: (remove the include)

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

    Always refer to the package official documentation, when you encounter errors specific to the package itself. (In this case is 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)).

    If you're using Django>=2, then the official document should explain the correct way to install this package.