Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DjangoAdmin adding weird characters to ImageField

Tags:

python

django

I have an ImageField for a "People" model..

models.py

from django.db import models
    
    class People(models.Model):
        firstname   = models.CharField(max_length=100)
        lastname    = models.CharField(max_length=100)
        img         = models.ImageField(upload_to='media/people')

The problem is, when I try to add a people object through Django Admin, and I select an image file, Django admin adds weird characters (that looks like a hash value) at the end of the image, which causes the image to not appear on the website..

For example, this is my Django Admin page for adding people:

enter image description here

When I click save and check my admin, this is what appears:

enter image description here

As you can see, it added "_PQSSbcg" at the end of the image name for some reason.. Because of this, the website fails to display the image, because the template tries to find "jose_atria.jpg"..

Why is Django Admin adding this extra characters, and how do I get rid of this?

Thanks

like image 401
user2436815 Avatar asked Feb 27 '15 22:02

user2436815


1 Answers

Addition of the random extra characters is because you have uploaded files with same name twice.

Deleting the previous existing file before uploading it again will help you

like image 68
Aswin Murugesh Avatar answered Oct 02 '22 01:10

Aswin Murugesh