Home > Software engineering >  Django admin filefield 404 on download
Django admin filefield 404 on download

Time:02-01

i have problems with my django app. Since a few days i have the problem that the download dont work on production but i cant find the reason why...

I can upload files and they are stored in the correct folder, but as soon as i click on it i get a 404 error "file not found.."

Here is my setup:

settings.py

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',
            ],
        },
    },
]

.
.
.
TEMPLATE_DIR = os.path.join(BASE_DIR, "templates")
STATIC_DIR = os.path.join(BASE_DIR, "static")
MEDIA_DIR = os.path.join(BASE_DIR, "media")

STATIC_ROOT = STATIC_DIR
STATIC_URL = '/static/'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "staticfiles/static"),
]

MEDIA_URL = '/media/'
MEDIA_ROOT = MEDIA_DIR
MEDIA_TEMPLATE_ROOT = os.path.join(MEDIA_ROOT, 'templates')
MEDIA_TEMP = os.path.join(MEDIA_ROOT, 'tmp')

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

urlpatterns = [
    path('jet/', include('jet.urls', 'jet')),
    path('admin/', admin.site.urls),
]   static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)   static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

I tried many different configurations of the media_url, media_root etc... without success..

CodePudding user response:

In production, usually the django web app is behind a web server like nginx or apache http web server.

In that case, what is usually done is to configure your web server (nginx or apache) to serve directly the static files, thus you need to configure the virtualhost section.

If you can provide more information about your configuration, I could be more specific.

CodePudding user response:

Thats the setup iam using: https://lab.uberspace.de/guide_django/

Its my first time deploying the app on a server. Debug=False yes. The app it self works but it doesnt serve the files. But i have no clue what gunicorn does in this configuration, i just followed the link above to set it up.

  • Related