Reuse media When saving uploaded pictures , The page does not read pictures , Console display page not found 404, The path is clearly right , Why can't I read the picture ? Because it didn't give media To configure url
step : Just copy mine directly
settings Set up media
MEDIA_URL = '/media/'
# Set the path to upload files
MEDIA_ROOT = os.path.join(BASE_DIR, 'media') # Specify the root directory
Folder with the same name as the project urls:
from django.views.static import serve # Upload file processing function
from .settings import MEDIA_ROOT # Import... From configuration MEDIA_ROOT
urlpatterns = [
url(r'^media/(?P<path>.*)$', serve, {"document_root":MEDIA_ROOT})
]
settings:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
# Add this sentence
'django.template.context_processors.media', # take media_url Upload file path register to template
],
},
},
]
And then in the corresponding page {%get_media_prefix%}{ {image.path}} that will do