MEDIA DERICTORY SETUP IN DJANGO


MODELS.PY

class Product(models.Model):
    image=models.ImageField(upload_to='images',default="")


SETTINFS.PY


import os
# Path where media is stored
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

# Base url to serve media files
MEDIA_URL = '/media/'

 

URLS.PY

from django.contrib import admin
from django.urls import path
from . import views

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


urlpatterns = [
  path('',views.index,name="index")
]
if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)

Comments

Popular posts from this blog

D WEB LINK