Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

managing media in django

#in base url  
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)
#in setting
MEDIA_URL='/media/
MEDIA_ROOT=BASE_DIR / 'media'
Comment

django add media

### add the following lines in Project settings.py ###

MEDIA_URL='/media/'
MEDIA_ROOT=BASE_DIR / 'media'

### add the following lines in Project urls.py ###

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

urlpatterns = [
    # put here your urls
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)


### now once you add another object a media folder will be created ###
### in the base folder and you can use it ###

### remember to add .url when viewing the image in html ###
### Ex. obj.Image_Propertey_Name.url ###
Comment

managing media in django

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)
Comment

media django

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 :: select a value randomly in a set python 
Python ::  
::  
::  
:: hide particular attribute in django admin 
Python ::  
::  
::  
::  
:: wait() in python tkinter 
:: opencv get contours 
:: ImportError: cannot import name ABC 
Python ::  
::  
::  
::  
Python :: drop columnd python 
:: django make migrations 
:: remove duplicate row in df 
:: matplotlib set number of decimal places 
::  
:: code for making an exe file for python 
::  
::  
::  
::  
Python ::  
::  
Python :: getting image from path python 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =