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
# ------------------------------------------------------------------------------
# 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/"
location /media/ {
alias /var/lib/dokku/data/storage/dokkuappname/;
}
dokkuappname volume bind-mounts:
/var/lib/dokku/data/storage/dokkuappname:/media
I wanted to see the path to Django's media folder. I put print(MEDIA_ROOT)
in base.py
to print the path during deployment. It was /app/my_app_dir/media
. I realized that /app
existed in Dokku documentation, but I always thought that it was a place holder like path/to/app
. No, it was the path.
dokku storage:mount app-name /var/lib/dokku/data/storage/node-js-app:/app/storage
I fixed my mount command:
dokku storage:mount my_app/var/lib/dokku/data/storage/my_app:/app/my_app_dir/media
and it finally worked!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.