Creating & Registering Folder for Media Uploads Django.How

Author avatar wrote on 26/05/2022

Go to settings.py file and register the folder


MEDIA_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_URL = '/media/'

Edit the urls.py file

1. Import from settings and static


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

 

2. Add to the end of the list


+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

 

Here is the full code


from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    path('', include('pages.urls')),
    path('listings/', include('listings.urls')),
    path('admin/', admin.site.urls),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

 

CRUDgen Django CRUD generator