开发者

django rename image in view

开发者 https://www.devze.com 2023-03-09 16:52 出处:网络
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.

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]

0

精彩评论

暂无评论...
验证码 换一张
取 消