[Fixed]-How to update a ContentFile's content (by overwriting the file)

1👍

instance.css_file is a FieldFile object, not a filename. You should use the name instead:

def form_valid(self, form):
    instance = self.object
    filename = instance.css_file.name
    ...
    instance.css_file.save(filename, filedata)
    super(CSSUpdate, self).save(form)
👤knbk

Leave a comment