Answer the question
In order to leave comments, you need to log in
How to save a local file in an ImageField in Django?
I am writing a new project on Django and finally decided to follow the TDD path. But I ran into a problem while testing the file upload. Because at the moment I don't have any forms yet, I just want to check the corresponding methods.
There is a class:
class Photos(models.Model):
#*тут много чего опущено, но сути оно не меняет - в таком варианте тоже не работает
photo_file = models.ImageField(upload_to=photos_storage)
def add_photo(self, photo_file):
with open(photo_file) as f:
my_file = File(f)
filename = "filename.jpg"
self.photo_file.save(filename, my_file)
AssertionError: 301202L is not 1830L
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question