0

While trying to upload a file using django cms filer I am getting the following error

`*Internal Server Error: /admin/filer/clipboard/operations/upload/1/
Traceback (most recent call last):
  File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/filer/admin/clipboardadmin.py", line 112, in ajax_upload
    file_obj.save()
  File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/filer/models/imagemodels.py", line 66, in save
    super().save(*args, **kwargs)
  File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/filer/models/abstract.py", line 107, in save
    super().save(*args, **kwargs)
  File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/filer/models/filemodels.py", line 279, in save
    super().save(*args, **kwargs)
  File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/polymorphic/models.py", line 87, in save
    return super().save(*args, **kwargs)
  File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django/db/models/base.py", line 726, in save
    self.save_base(using=using, force_insert=force_insert,
  File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django/db/models/base.py", line 762, in save_base
    parent_inserted = self._save_parents(cls, using, update_fields)
  File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django/db/models/base.py", line 791, in _save_parents
    updated = self._save_table(
  File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django/db/models/base.py", line 868, in _save_table
    results = self._do_insert(cls._base_manager, using, fields, returning_fields, raw)
  File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django/db/models/base.py", line 906, in _do_insert
    return manager._insert(
  File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django/db/models/query.py", line 1270, in _insert
    return query.get_compiler(using=using).execute_sql(returning_fields)
  File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django/db/models/sql/compiler.py", line 1409, in execute_sql
    for sql, params in self.as_sql():
  File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django/db/models/sql/compiler.py", line 1352, in as_sql
    value_rows = [
  File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django/db/models/sql/compiler.py", line 1353, in <listcomp>
    [self.prepare_value(field, self.pre_save_val(field, obj)) for field in fields]
  File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django/db/models/sql/compiler.py", line 1353, in <listcomp>
    [self.prepare_value(field, self.pre_save_val(field, obj)) for field in fields]
  File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django/db/models/sql/compiler.py", line 1304, in pre_save_val
    return field.pre_save(obj, add=True)
  File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django/db/models/fields/files.py", line 301, in pre_save
    file.save(file.name, file.file, save=False)
  File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/filer/fields/multistorage_file.py", line 120, in save
    super().save(name, content, save)
  File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/easy_thumbnails/files.py", line 643, in save
    super().save(name, content, *args, **kwargs)
  File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django/db/models/fields/files.py", line 87, in save
    name = self.field.generate_filename(self.instance, name)
  File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django/db/models/fields/files.py", line 320, in generate_filename
    return self.storage.generate_filename(filename)
  File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django/core/files/storage.py", line 108, in generate_filename
    return os.path.normpath(os.path.join(dirname, self.get_valid_name(filename)))
  File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django_storage_url/backends/not_implemented.py", line 14, in get_valid_name
    raise NotImplementedError
NotImplementedError
[20/Feb/2023 09:27:05] "POST /admin/filer/clipboard/operations/upload/1/?qqfile=img0.jpg HTTP/1.1" 500 187409
[20/Feb/2023 09:27:05] "GET /admin/filer/folder/1/list/?order_by=-modified_at HTTP/1.1" 200 16717
*`

I used the default installation of DjangoCMS from git@github.com:django-cms/django-cms-quickstart.git I only modified the DATABASE settings so it uses sqlite

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}

Here is my full settings file

from pathlib import Path
import os
import dj_database_url
from django_storage_url import dsn_configured_storage_class

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get('SECRET_KEY', '<a string of random characters>')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.environ.get('DEBUG') == "True"

ALLOWED_HOSTS = [os.environ.get('DOMAIN'),]
DEBUG = True
ALLOWED_HOSTS = ["localhost",]
if DEBUG:
    ALLOWED_HOSTS = ["*",]

# Redirect to HTTPS by default, unless explicitly disabled
#SECURE_SSL_REDIRECT = os.environ.get('SECURE_SSL_REDIRECT') != "False"

X_FRAME_OPTIONS = 'SAMEORIGIN'


# Application definition

INSTALLED_APPS = [
    'backend',

    # optional, but used in most projects
    'djangocms_admin_style',

    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'whitenoise.runserver_nostatic',  # http://whitenoise.evans.io/en/stable/django.html#using-whitenoise-in-development
    'django.contrib.staticfiles',
    'django.contrib.sites',

    # key django CMS modules
    'cms',
    'menus',
    'treebeard',
    'sekizai',

    # Django Filer - optional, but used in most projects
    'filer',
    'easy_thumbnails',

    # the default CKEditor - optional, but used in most projects
    'djangocms_text_ckeditor',

    # some content plugins - optional, but used in most projects
    'djangocms_file',
    'djangocms_icon',
    'djangocms_picture',
    'djangocms_style',
    'djangocms_googlemap',
    'djangocms_video',

    # optional django CMS Frontend modules
    'djangocms_frontend',
    'djangocms_frontend.contrib.accordion',
    'djangocms_frontend.contrib.alert',
    'djangocms_frontend.contrib.badge',
    'djangocms_frontend.contrib.card',
    'djangocms_frontend.contrib.carousel',
    'djangocms_frontend.contrib.collapse',
    'djangocms_frontend.contrib.content',
    'djangocms_frontend.contrib.grid',
    'djangocms_frontend.contrib.jumbotron',
    'djangocms_frontend.contrib.link',
    'djangocms_frontend.contrib.listgroup',
    'djangocms_frontend.contrib.media',
    'djangocms_frontend.contrib.image',
    'djangocms_frontend.contrib.tabs',
    'djangocms_frontend.contrib.utilities',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.locale.LocaleMiddleware',

    'cms.middleware.user.CurrentUserMiddleware',
    'cms.middleware.page.CurrentPageMiddleware',
    'cms.middleware.toolbar.ToolbarMiddleware',
    'cms.middleware.language.LanguageCookieMiddleware',
]

ROOT_URLCONF = 'backend.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'django.template.context_processors.media',
                'django.template.context_processors.csrf',
                'django.template.context_processors.tz',
                'django.template.context_processors.i18n',

                'cms.context_processors.cms_settings',
                'sekizai.context_processors.sekizai',

            ],
        },
    },
]

THUMBNAIL_PROCESSORS = (
    'easy_thumbnails.processors.colorspace',
    'easy_thumbnails.processors.autocrop',
    #'easy_thumbnails.processors.scale_and_crop',
    'filer.thumbnail_processors.scale_and_crop_with_subject_location',
    'easy_thumbnails.processors.filters',
)


CMS_TEMPLATES = [
    # a minimal template to get started with
    ('minimal.html', 'Minimal template'),

    # optional templates that extend base.html, to be used with Bootstrap 5
    ('bootstrap5.html', 'Bootstrap 5 Demo'),

    # serving static files with whitenoise demo
    ('whitenoise-static-files-demo.html', 'Static File Demo'),
]

WSGI_APPLICATION = 'backend.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases

# Configure database using DATABASE_URL; fall back to sqlite in memory when no
# environment variable is available, e.g. during Docker build
#DATABASE_URL = os.environ.get('DATABASE_URL', 'sqlite://:memory:')
#DATABASES = {'default': dj_database_url.parse(DATABASE_URL)}

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}



DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'

# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators

if not DEBUG:
    AUTH_PASSWORD_VALIDATORS = [
        {
            'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
        },
        {
            'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
        },
        {
            'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
        },
        {
            'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
        },
    ]


# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/

LANGUAGE_CODE = 'en'

LANGUAGES = [
    ('en', 'English'),
]

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles_collected')
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

# Media files
# DEFAULT_FILE_STORAGE is configured using DEFAULT_STORAGE_DSN

# read the setting value from the environment variable
DEFAULT_STORAGE_DSN = os.environ.get('DEFAULT_STORAGE_DSN')

# dsn_configured_storage_class() requires the name of the setting
DefaultStorageClass = dsn_configured_storage_class('DEFAULT_STORAGE_DSN')

# Django's DEFAULT_FILE_STORAGE requires the class name
DEFAULT_FILE_STORAGE = 'backend.settings.DefaultStorageClass'

# only required for local file storage and serving, in development
MEDIA_URL = 'media/'
MEDIA_ROOT = os.path.join('/data/media/')


SITE_ID = 1

Oleg Rud
  • 11
  • 1

1 Answers1

0

It looks like you've not got the project configured with any storage. This is likely why you're seeing the NotImplementedError get raised.

The quickstart project is there to get a django-cms project up and running as easily as possible, but it doesn't have everything ready to go straight away. Things like storage need some decision making on where to put files by the developer running the project.

Storage is configured using the DEFAULT_STORAGE_DSN environment variable which can be seen in the settings on line 208.

There's some more docs on this topic here.

I'm tech lead for the django-cms association. I suggest you take a look at our support channels and if you use slack, come and join us on there any post in the #support channel.

https://www.django-cms.org/en/support/

markwalker_
  • 12,078
  • 7
  • 62
  • 99