[Answer]-Viewing images uploaded to Django Admin

1👍

Docs are here https://docs.djangoproject.com/en/dev/ref/settings/#media-root

You need to set MEDIA_ROOT and MEDIA_URL in your settings file like this

MEDIA_ROOT = /var/www/example.com/media/
MEDIA_URL = /media

and your upload_to should probably be the model name or something to identify it.

image = models.ImageField(upload_to='image')

Then the link should point the /media/image/NAME_OF_IMAGE.png

You will also need to have urls.py setup to server media files. For production you would want to do this in nginx with an alias. See https://docs.djangoproject.com/en/dev/howto/static-files/#serving-files-uploaded-by-a-user-during-development

Which says:

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)

Leave a comment