django 404,页面未找到页面未找到

toe95027  于 2022-12-14  发布在  Go
关注(0)|答案(1)|浏览(101)

我最近开始学习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.

我真的不知道该怎么办了,我什么都试过了。难道有人也遇到了这个问题?

jogvjijk

jogvjijk1#

我只需要改变MEDIA_URLMEDIA_ROOT的位置

MEDIA_URL = '/media/
    MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

相关问题