I want to rename an image that is uploaded with a Modelform and I want to do this in the view because the path depends on the user who uploaded it. So far i have this:
if request.method == 'POST':
form = AddImageForm(request.POST, request.FILES)
if form.is_valid():
new_image = form.save(commit=false)
But how do I get the image, rename it and save it. (Maybe I will also do some additional proccessing like resizing, 开发者_StackOverflowetc.) I'm quite new to python an Django and I have no clue how to manipulate files.
Best Jacques
the os
module lets you interact with the filesystem, and the data in the all the uploaded files is available in the dict request.FILES.
Django file upload docs
so maybe you would do request.files.items()[0][1]
精彩评论