在页面视图中找不到 Django 图像,但在 post 请求后保存
Django images not found in page view but was save after post request
我试图保存图像,但无法通过浏览器显示。它已成功保存在确切位置,但当我粘贴 link 时,它显示“找不到页面”。有人可以帮助我了解发生了什么吗?
查看输出:
Browser View
代码:
Code Snippet
设置配置:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
STATIC_LOCATION = "static"
MEDIA_LOCATION = "media"
settings.py
from pathlib import Path
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
urls.py
这必须在您的设置配置中应用。
from django.conf.urls.static import static
from django.conf import settings
urlpatterns = [
....
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
我试图保存图像,但无法通过浏览器显示。它已成功保存在确切位置,但当我粘贴 link 时,它显示“找不到页面”。有人可以帮助我了解发生了什么吗?
查看输出: Browser View
代码: Code Snippet
设置配置:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
STATIC_LOCATION = "static"
MEDIA_LOCATION = "media"
settings.py
from pathlib import Path
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
urls.py
这必须在您的设置配置中应用。
from django.conf.urls.static import static
from django.conf import settings
urlpatterns = [
....
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)