[Fixed]-Django ModelForm for updating model doesn't save Image and throws an error

1👍

You’re trying to upload the image to img/, which is not a valid Windows path (backslash separators). If you want it to work in both Linux and Windows, you could do something like:

import os

def get_image_path(instance, filename):
    return os.path.join("img", filename)

class Page(models.Model):
    ...
    img = models.ImageField(upload_to=get_image_path, blank=True, null=True)
    ...

Leave a comment