Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 未正确找到/加载图像-404_Python_Django_Django Oscar - Fatal编程技术网

Python 未正确找到/加载图像-404

Python 未正确找到/加载图像-404,python,django,django-oscar,Python,Django,Django Oscar,我正在使用该项目,并遵循教程 网站已经启动并运行,但是,当我从管理仪表板添加产品并上传图片时,缩略图没有加载,当我在客户视图上查看产品时,图片丢失 以下是我在settings.py文件中的配置: 静态URL='/STATIC/' 媒体URL='/MEDIA/' 媒体根=位置(“公共/媒体”) 静态根=位置('公共/静态') 当我从客户视图查看产品时,终端显示404 GET “GET/media/cache/45/ec/45ecfa87510d3ed6997925b6e26ed7.jpg HTTP

我正在使用该项目,并遵循教程

网站已经启动并运行,但是,当我从管理仪表板添加产品并上传图片时,缩略图没有加载,当我在客户视图上查看产品时,图片丢失

以下是我在settings.py文件中的配置:

静态URL='/STATIC/'
媒体URL='/MEDIA/'
媒体根=位置(“公共/媒体”)
静态根=位置('公共/静态')

当我从客户视图查看产品时,终端显示404 GET

“GET/media/cache/45/ec/45ecfa87510d3ed6997925b6e26ed7.jpg HTTP/1.1”4044880

这是它的样子

当我转到网站的管理部分并尝试单击产品表中的图片时,它也会显示“未找到页面”,这次的URL是

当我浏览到特定的产品(仍然在管理网站上),然后该产品的图像部分,缩略图不会显示,终端会显示这一点

“GET/media/cache/cd/8a/cd8af791d513ec91a583b073070d9a7.jpg HTTP/1.1”4044880

下面是URL.py中的模式

URL模式=[ url(r“^i18n/”,包括('django.conf.urls.i18n')

我在Finder中看到这条路径下的图片

/frobshop/frobshop/public/media/images/products/2017/09

任何有助于解决这个问题的人都将不胜感激


谢谢!

您需要在
URL.py的底部添加以下内容:

from django.conf import settings
if settings.DEBUG:
    from django.conf.urls.static import static
    from django.contrib.staticfiles.urls import staticfiles_urlpatterns
    # Serve static and media files from development server
    urlpatterns += staticfiles_urlpatterns()
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
这仅限于当
settings.DEBUG==True时,因为在生产中,您将希望使用nginx或等效工具为静态和媒体提供服务


Oscar文档中没有涉及到这一点,因为这是Django级别的问题,但可能应该提到。

您需要在
URL.py的底部添加以下内容:

from django.conf import settings
if settings.DEBUG:
    from django.conf.urls.static import static
    from django.contrib.staticfiles.urls import staticfiles_urlpatterns
    # Serve static and media files from development server
    urlpatterns += staticfiles_urlpatterns()
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
这仅限于当
settings.DEBUG==True时,因为在生产中,您将希望使用nginx或等效工具为静态和媒体提供服务

Oscar文档中没有涉及到这一点,因为它是Django级别的问题,但可能应该提到它