I'm trying to figure out why I'm having problems with file upload in Django... I made sure to create the directory and also made sure it has the appropriate permissions. This is working on my local machine; but failing with "Bad Request (400)" when I'm running it on OpenShift. I did get it working once, but it stopped working after that and I can't figure it out; I would greatly appreciate a second set of eyes.
The File module code:
from django.db import modelsfrom django.dispatch import receiverfrom BAGCA.settings import MEDIA_ROOT_FILESclass Files(models.Model): class Meta: verbose_name_plural = "Files" def __str__(self): return u'%s' % self.filename filename = models.CharField(max_length=100) file = models.FileField(upload_to=MEDIA_ROOT_FILES)# These two auto-delete files from filesystem when they are unneeded:@receiver(models.signals.post_delete, sender=Files)def auto_delete_file_on_delete(sender, instance, **kwargs): """Deletes file from filesystem when corresponding `Files` object is deleted. """ if instance.file: if os.path.isfile(instance.file.path): os.remove(instance.file.path)@receiver(models.signals.pre_save, sender=Files)def auto_delete_file_on_change(sender, instance, **kwargs): """Deletes file from filesystem when corresponding `Files` object is changed. """ if not instance.pk: return False try: old_file = Files.objects.get(pk=instance.pk).file if not old_file: return False except Files.DoesNotExist: return False new_file = instance.file if not old_file == new_file: if os.path.isfile(old_file.path): os.remove(old_file.path)
And my files are a few kb; nothing gigantic