Configuration about django file upload and browsing

The configuration above

#urlmapping
MEDIA_URL = '/media/'
#Set the static file path to the home directory
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

where base_dir is

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

MEDIA_YRL: is a mapped address that needs to be used with routing

 
 
from django.conf.urls.static import static
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

It can be a route anywhere, but it is recommended to put it under the following route. If it is not the same as the route access address, you need to add the name of the app


Notice: 

'django.contrib.staticfiles' module needs to be added to INSTALLED_APPS

INSTALLED_APPS = [
  ...
  'django.contrib.staticfiles',
  ...
]










Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325764581&siteId=291194637