Wednesday, May 19, 2021

How to Setup Static and Media Files in Django

How to Setup Static and Media Files in Django


 

Settings.py
import os
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
urls.py
 
#import files
from django.conf import settings
from django.conf.urls.static import static

#paste it bottom of the url

urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Open Terminal:
python manage.py collectstatic
Thank you .happy coding!



Previous Post
First

0 Comments: