Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

static and media files in django

# in settings.py
STATIC_URL = '/static/'
STATICFILES_DIRS = [ BASE_DIR / "static" ]
STATIC_ROOT = "static_root"
MEDIA_URL = '/media/'
MEDIA_ROOT = "media_root"

# in ulrs.py
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [ ... ]
if settings.DEBUG:
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
	urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
# in .gitignore add media_root, static_root
Comment

django static media

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

urlpatterns = [
    # ... the rest of your URLconf goes here ...
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

# ----------------or----------------

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

Comment

PREVIOUS NEXT
Code Example
Python :: python get base directory 
Python :: python read excel set index 
Python :: square finder python 
Python :: getting dummies for a column in pandas dataframe 
Python :: is string python 
Python :: pandas split column into multiple columns by delimiter 
Python :: check empty dataframe 
Python :: quadratic formula python 
Python :: snowflake python connector error handling 
Python :: how to make a alert box in python 
Python :: use miraculous with token 
Python :: gluten 
Python :: SerialClient.py", line 41, in <module import queue ImportError: No module named queue 
Python :: How to get key value list from selection fields in Odoo 10 
Python :: python program for simple interest 
Python :: pandas rename columns by position 
Python :: how to put iput python 
Python :: program to segregate positive and negative numbers in same list 
Python :: python make a shop menu 
Python :: get most repeated instance in a queryset django 
Python :: python collections counter 
Python :: new column with age interval pandas 
Python :: python make integer into a list 
Python :: read csv boto3 
Python :: how to put more than one file type in pysimplegui 
Python :: discord.py ping command 
Python :: YouCompleteMe unavailable: requires Vim compiled with Python (3.6.0+) support. 
Python :: pd.merge left join 
Python :: sheebang python 
Python :: python pandas convert nan to 0 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =