Categorized: Django

I question some of what I'm saying here, but it's not total crap either.

Howto Upload Images in Django

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.

Comments

romo → August 3rd, 2007 at 11:45 am

Woah! Thank you very much!

kira → January 30th, 2009 at 9:36 pm

Thanks, found this helpful as well.

naz → October 3rd, 2009 at 2:36 pm

You are my hero.

Sebastián → December 11th, 2009 at 6:21 am

I’m gonna make you a monument! well, maybe not, but this really helped me, thanks a lot!

What do you think about that?

Elsewhere in the empire: Home, Blog, APOD