I faced the same problem
the problem here is the name of the image "file"
I think it is working good at development server and gives error at production server
this needs some configuration to make the server can serve files with names like this.
to be in a safe side with urls and file names that will be in urls
as mentioned her https://stackoverflow.com/a/1547940/6840261
i came up with solution to change the name of the file or image if it wasn't in proper shape as this answer mention https://stackoverflow.com/a/1547940/6840261
i am
not generating names i only name the file 'a.thesameextension_of_thefile' and django handle multiple files with the same name
you have to add code at save() to apply in every change or addition of a new model
class City(models.Model):
name = models.CharField(max_length=100, verbose_name=_("City Name"),
validators=[RegexValidator(r'^[\u0621-\u064A\u0660-\u0669]+$')])
city_image = models.ImageField(upload_to='city/images/', blank=False, null=True, verbose_name=_("City Image"))
def save(self, force_insert=False, force_update=False, using=None,
update_fields=None):
name = self.city_image.name
extension = name.split('.')[-1]
for char in name:
if char not in 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.':
self.city_image.name = 'a' + '.' + extension
break
instance = super(City, self).save(force_insert=False, force_update=False, using=None,
update_fields=None)
this solution will work well , there is another solution as i mentioned in my own question but i think its not a good one as you will have to add code to the core of django request handler and wsgi
you can check it How to fix [ERROR] [2699022] wsgiHandler pApp->start_response() return NULL?