1

django-oscar wasn't displaying pictures of products when the media_root was outside the project root, so changing the media_root to project_root/public/media throws this error.

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)

And also why were the images not showing when the media_root was outside, thought it was safer that way. Thanks
I have tried to makemigrations and migrate, but it still gives me the same error.

alfiepoleon
  • 1,781
  • 1
  • 16
  • 18
  • Possible duplicate of [Suspicious File Operation..The joined path ... is located outside of the base path component](http://stackoverflow.com/questions/33625173/suspicious-file-operation-the-joined-path-is-located-outside-of-the-base-pa) – wogsland Jan 12 '16 at 02:32

2 Answers2

0

I added this to my urls.py and solved the media_root problem

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

Make sure you have the code below in settings.py

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

and

In projects urls.py add this code

urlpatterns = urlpatterns + static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)
Chalist
  • 3,160
  • 5
  • 39
  • 68