4

I deployed mu project in heroku successfully.

The only problem is that I can't find media files on heroku.

When I type .../media/pic1.png locally , I get the picture in the browser.

But, in heroku,, that gives

Page not found (404)
Request Method: GET
Request URL: ...../media/pic1.png
Raised by: django.views.static.serve

Path ...../media/pic1.png doesn't exist

settings.py

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

project/urls.py

urlpatterns = [
  url(r'^admin/', admin.site.urls),
  url(r'^admin_platform/', include('admin_platform.urls')),
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
M. Dhaouadi
  • 617
  • 10
  • 27

1 Answers1

0

Your setting.py should look something like this:-

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')#by doing this there will be media folder in your main directory.

And in your url.py your code should be like this:-

urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^admin_platform/', include('admin_platform.urls')),
]

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)#this will help to access your media folder.

Hope this help in your project. :-)