Home > Enterprise >  Django images not found in page view but was save after post request
Django images not found in page view but was save after post request

Time:10-24

I was trying to save an image but it can't be displayed through the browser. It was successfully saved in the exact location but when I pasted the link it says, "Page not found". Could someone help me with what's going on?

See output: Browser View

Code: Code Snippet

Settings configuration:

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

STATIC_LOCATION = "static"
MEDIA_LOCATION = "media"

CodePudding user response:

settings.py
from pathlib import Path

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
urls.py
This must be applied in your settings configuration.
from django.conf.urls.static import static
from django.conf import settings

urlpatterns = [
    ....
]   static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
  • Related