I deployed my Django app on server with Dokku. Staticfiles seems to be working as CSS is perfectly fine in admin dashboard, I can upload file but I cannot reach the file.
I discovered that I should be using Dokku persistence storage anyway. So I set it up (I suppose). Then I setup my Nginx. Before Nginx, Django was showing "page not found" for the file path. Now, I get "The page you were looking for doesn't exist.".
How can I correctly connect my app to persistence storage?
Edit:
I manually added a file to /var/lib/dokku/data/storage/dokkuappname
and was able to download. So Nginx is working but Django is not using storage folder as media folder.
Static and media settings on Django
# STATIC
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#static-root
STATIC_ROOT = str(ROOT_DIR / "staticfiles")
# https://docs.djangoproject.com/en/dev/ref/settings/#static-url
STATIC_URL = "/static/"
# https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS
STATICFILES_DIRS = [str(APPS_DIR / "static")]
# https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders
STATICFILES_FINDERS = [
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
]
# MEDIA
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#media-root
MEDIA_ROOT = str(APPS_DIR / "media")
# https://docs.djangoproject.com/en/dev/ref/settings/#media-url
MEDIA_URL = "/media/"
Nginx media.conf settings
location /media/ {
alias /var/lib/dokku/data/storage/dokkuappname/;
}
dokku storage:list dokkuappname result
dokkuappname volume bind-mounts:
/var/lib/dokku/data/storage/dokkuappname:/media
question from:
https://stackoverflow.com/questions/65930224/how-to-connect-django-media-storage-to-dokku-persistence-storage 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…