Howto Upload Images in Django

Posted by Trey on February 27, 2007

Previously

I’ve chosen to keep my media in the /media/ folder of the same site (I know Django-people prefer to keep media on a separate server, but I don’t want to do that for a small-ish site, which is why I’d be likely to use Django).

In settings.py:

ADMIN_MEDIA_PREFIX = '/admin_media/'

This defaults to /media/, but I want that for my own media.

In urls.py:

(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': '/Users/username/django/django_projects/project_name/media'}),

This is recommended against here. But that’s because they want you to serve all your static files from a separate server/domain as I mentioned before.

Set the other media configuration things:

MEDIA_ROOT = '/Users/username/django/django_projects/project_name/media/'
MEDIA_URL = '/media/'

In models.py:

logo = models.ImageField(upload_to="images/logos/", blank=True, help_text="Should be 50px wide")

This guy was having the same problem.

Technorati Tags: