Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork371
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? |
BetaWas this translation helpful?Give feedback.
All reactions
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
fromdjango.confimportsettingsfromdjango.conf.urls.staticimportstatic...ifsettings.DEBUG:urlpatterns+=static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)
.gitignore
# Media filesmedia_collected/
Replies: 2 comments
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
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. |
BetaWas this translation helpful?Give feedback.
All reactions
-
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 fromdjango.confimportsettingsfromdjango.conf.urls.staticimportstatic...ifsettings.DEBUG:urlpatterns+=static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT) .gitignore # Media filesmedia_collected/ |
BetaWas this translation helpful?Give feedback.