-1

My settings.py

MEDIA_ROOT='/static/'

MEDIA_URL='media'

My urls.py

from django.conf import settings
from django.conf.urls.static import static

urlpatterns=[
#all routes
]

if settings.DEBUG:
   urlpatterns+=static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

This code works fine many time but this is not working, I don't know why?

Sunderam Dubey
  • 1
  • 11
  • 20
  • 40
  • Does this answer your question? [Why image is not getting saved in media directory in django?](https://stackoverflow.com/questions/68179323/why-image-is-not-getting-saved-in-media-directory-in-django) – rs_punia Mar 05 '22 at 11:58

2 Answers2

1

You haven't defined BASEDIR and you are defining it wrong way.

Try this:

Settings.py

MEDIA_URL= '/media/'
MEDIA_ROOT=BASE_DIR / 'media'
Sunderam Dubey
  • 1
  • 11
  • 20
  • 40
0

could it just be urlpatterns += static

  • 1
    Yes, I have made the typo while writing the question, actually I already wrote this in my editor. –  Mar 05 '22 at 08:28