Search code examples
pythondjangodjango-templatesdjango-viewsdjango-oscar

SuspiciousFileOperation at /index/


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.


Solution

  • 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,}),
                            )