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 :: is prime in python 
Python :: pandas read google sheet 
Python :: letter frequency counter python 
Python :: accuracy score 
Python :: python version kali linux 
Python :: how to sort dictionary in python by value 
Python :: discord.py cog 
Python :: get columns that contain null values pandas 
Python :: how to create a python venv 
Python :: install qt designer python ubuntu 
Python :: pytohn epsilon 
Python :: puissance python 
Python :: python inline conditional 
Python :: python open file relative to module 
Python :: python get dict values as list 
Python :: django get or 404 
Python :: python delete file with extension 
Python :: ipython read audio file 
Python :: json python no whitespace 
Python :: plt.plot figure size 
Python :: print a text in python 
Python :: static class python 
Python :: how to encrypt a string python 
Python :: screen size python 
Python :: python empty text file 
Python :: weekday pandas 
Python :: how to send emails in python 
Python :: sneaker bots 
Python :: remove empty lines from file python 
Python :: value_count pandas change column name 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =