Replacing a Django image doesn't delete original

前端 未结 8 1315
死守一世寂寞
死守一世寂寞 2020-12-13 14:43

In Django, if you have a ImageFile in a model, deleting will remove the associated file from disk as well as removing the record from the database.

Shouldn\'t replac

8条回答
  •  粉色の甜心
    2020-12-13 15:08

    I used a simple method with popen, so when i save my Info model i delete the former file before linking to the new:

    import os
    
    try:
        os.popen("rm %s" % str(info.photo.path))
    except:
        #deal with error
        pass
    info.photo = nd['photo']
    

提交回复
热议问题