Categorized: Django
I question some of what I'm saying here, but it's not total crap either.
Howto Upload Images in Django
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
Woah! Thank you very much!
Thanks, found this helpful as well.
You are my hero.
I’m gonna make you a monument! well, maybe not, but this really helped me, thanks a lot!
hay i tried to upload the file using the template but it didnt work. On the other side when i tried this thing with admin interface it works fine. i dont know wats the reason. any idea ,,,,,,,,?
What do you think about that?