Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Django Media Files#37

Answeredbydaronzwink
daronzwink asked this question inQ&A
Discussion options

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?

You must be logged in to vote

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

Comment options

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 insrc/config/settings.py, this would happen with or without Docker.

https://docs.djangoproject.com/en/4.2/topics/http/file-uploads/ has a few examples of uploading files.

You must be logged in to vote
0 replies
Comment options

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/
You must be logged in to vote
0 replies
Answer selected bydaronzwink
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@daronzwink@nickjj

[8]ページ先頭

©2009-2025 Movatter.jp