1

I'm a noob in Django framework, sorry for misunderstanding in some concepts. Currently, I'm trying to set up a Django app with django-filer. Django filer was installed commonly and migrations were done according to documentation. The installed apps list was updated with filer, mptt, and easy_thumbnails. The allowed host was updated with the IP of the host, debug flag was set to true and timezones and language code were also updated, as shown below. According to documentation, that's all for a basic setup of Django filer.

from pathlib import Path

BASE_DIR = Path(__file__).resolve().parent.parent
DEBUG = True
ALLOWED_HOSTS = ["192.168.230.98"]

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'filer',
    'mptt',
    'easy_thumbnails'
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    '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',
]

ROOT_URLCONF = 'filerTest.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',
            ],
        },
    },
]

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

USE_I18N = True
USE_TZ = True

STATIC_URL = 'static/'
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

Two images were uploaded through the Django admin interface. After images are upload, the Django admin interface can't retrieve they. Chrome development console showed a 404 error, like if images were not stored. When I check if images were stored, They are in a random names subfolder in the filer_public and file_public_thumbnails directories, according to other forums, this is the expectable behavior.

I try to set static_url parameter in settings.py. However, it's only possible to set one path. Then, I should choose between filer_public or filer_public_thumbnails or static directories to serve static files. This is not a good approach.

Django admin not retrieve image

Error from Django when try to expand or open image in a separate window

Some idea about what step or error I done during Django filer setup?

CDRM
  • 23
  • 6
  • Did you add the Django-filer urls to your project? See https://django-filer.readthedocs.io/en/latest/installation.html#canonical-urls – kimbo Dec 01 '22 at 15:25
  • Yes, I add to urlpatterns. from django.contrib import admin from django.urls import path, re_path, include urlpatterns = [ path('admin/', admin.site.urls), re_path(r'^filer/', include('filer.urls')) ] – CDRM Dec 01 '22 at 15:41
  • But I have a doubt, django-filer should create a directory filer? Where is filer.urls file? – CDRM Dec 01 '22 at 15:43
  • 1
    https://github.com/django-cms/django-filer/blob/master/filer/urls.py – kimbo Dec 01 '22 at 17:02
  • 1
    URL should be `/filer/canonical//` – kimbo Dec 01 '22 at 17:05
  • But URL in the second image is generated by Django, I can't modify this URL. With respect to URL filer file, the directory filer should be created by filer during installation or migration? I don't have this directory on my project. The documentation doesn't show specifications about this directory or how create it. – CDRM Dec 01 '22 at 17:14
  • After adding the filer folder and urls.py file, the problem persists yet. – CDRM Dec 01 '22 at 17:20
  • 1
    This might answer your question- https://stackoverflow.com/a/56743492/9638991 – kimbo Dec 01 '22 at 17:23
  • you're right. Add MEDIA_ROOT and MEDIA_URL to settings.py fixed the problem. Thanks a lot !!! Could you put the solution in an Answer to approve your solution? please? – CDRM Dec 01 '22 at 20:17
  • We could probably just mark this question as a duplicate of the one I linked, what do you think? – kimbo Dec 01 '22 at 20:20
  • If this is the right way. I don't have any problem with that (Y) – CDRM Dec 01 '22 at 20:22

0 Answers0