1

I have correctly set the settings for media in settings.py as:-

MEDIA_URL = '/media/'

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

and also specified the correct url settings

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

Whenever i upload an image through admin..the image gets uploaded in my media folder but i can't see it when i run my development server...it shows a page not found (404) error...

I think the problem is due to some permissions of uploaded files which is why django shows a 404 page when trying to access them..if someone knows about this please help

Please suggest me a solution Thank you!

Anshdeep singh
  • 63
  • 1
  • 1
  • 6
  • I copy-pasted your settings to a clean Django 1.7 app and it worked. Can you show something more? – Kos May 07 '15 at 15:05

2 Answers2

3

Try this:

from django.conf import settings
from django.conf.urls.static import static

urlpatterns = patterns('',
    # ... the rest of your URLconf goes here ...
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Relevant url:

https://docs.djangoproject.com/en/1.7/howto/static-files/#serving-files-uploaded-by-a-user-during-development

Jorick Spitzen
  • 1,559
  • 1
  • 13
  • 25
1

Do this


  from django.conf.urls.static import static
  from django.conf import settings

  urlpatterns = patterns('',

  # your urls here. 

  ) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Othman
  • 2,942
  • 3
  • 22
  • 31