Django Media Files #37
-
I am attempting to configure support for uploading of files to Django, but not able to figure out what configuration changes are needed to support serving media files and making them available through the docker configuration (similar to how static files are available). Has anyone had any luck adding the configuration needed for this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi, What does your current configuration look like? Is there something specific to this project that's preventing it from working? The static directory is configured in https://docs.djangoproject.com/en/4.2/topics/http/file-uploads/ has a few examples of uploading files. |
Beta Was this translation helpful? Give feedback.
-
I may have been overthinking the configuration and I now have media files working. My configuration updates are below, and hopefully they look correct and can help others out. src/config/settings.py # Media files
# https://docs.djangoproject.com/en/4.2/topics/files/
MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(BASE_DIR, "media_collected") src/config/urls.py from django.conf import settings
from django.conf.urls.static import static
...
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) .gitignore # Media files
media_collected/ |
Beta Was this translation helpful? Give feedback.
I may have been overthinking the configuration and I now have media files working. My configuration updates are below, and hopefully they look correct and can help others out.
src/config/settings.py
src/config/urls.py
.gitignore