我最近开始学习Django,但我仍然在为访问媒体文件而挣扎。我的settings.py文件包括以下内容:
STATIC_URL = '/static/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/
我的urls.py项目目录中包含以下内容。
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('store.urls'))
]
if st.DEBUG:
urlpatterns += django_Static(st.MEDIA_URL, document_root=st.MEDIA_ROOT)
当我尝试通过GET请求加载图像时,我得到以下消息:“
Page not found (404)
...
Using the URLconf defined in ecommerce_project.urls, Django tried these URL patterns, in this order:
admin/
[name='store_homepage']
^media/(?P<path>.*)$
The current path, media/product_pictures/256132756_922283745365869_1303861998719790800_n.jpg, matched the last one.
我真的不知道该怎么办了,我什么都试过了。难道有人也遇到了这个问题?
1条答案
按热度按时间jogvjijk1#
我只需要改变
MEDIA_URL
和MEDIA_ROOT
的位置