【问题标题】:SuspiciousFileOperation at /index//index/ 处的可疑文件操作
【发布时间】:2016-01-12 02:28:56
【问题描述】:

当 media_root 位于项目根目录之外时,django-oscar 没有显示产品图片,因此将 media_root 更改为 project_root/public/media 会引发此错误。

SuspiciousFileOperation at /index/ 
The joined path (.../barbaranew/media/media_root/images/products/malaysian1.png) is located outside of the base path component (.../barbaranew/barbaralee_site/public/media)

还有为什么当 media_root 在外面时图像没有显示,我认为这样更安全。 谢谢
我尝试进行迁移和迁移,但它仍然给我同样的错误。

【问题讨论】:

标签: python django django-templates django-views django-oscar


【解决方案1】:

我将它添加到我的 urls.py 并解决了 media_root 问题

if settings.DEBUG:
urlpatterns += patterns('',
                        url(r'^media/(?P<path>.*)$',
                            'django.views.static.serve',
                            {'document_root': settings.MEDIA_ROOT,}),
                        )

【讨论】:

    【解决方案2】:

    确保您在 settings.py 中有以下代码

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

    在项目 urls.py 中添加此代码

    urlpatterns = urlpatterns + static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-22
      • 1970-01-01
      • 1970-01-01
      • 2014-03-27
      • 2014-10-16
      • 2013-01-27
      • 1970-01-01
      • 2013-09-09
      相关资源
      最近更新 更多