圖像上傳和重命名django。

[英]Image upload and rename with django


I'm having trouble getting this to work:

我很難讓它工作:

def _get_image_name(filename):
    return 'asdf'


class ImageUploadForm(forms.Form):
    name = forms.CharField()
    file = forms.ImageField(upload_to=_get_image_name)

When running this, I'm getting "init() got an unexpected keyword argument 'upload_to'". My django version is 1.6.

運行時,我將獲得“init()獲得一個意外的關鍵字參數'upload_to'”。我的django版本是1.6。

2 个解决方案

#1


1  

The upload_to parameter is for models.ImageField only. The forms.ImageField you're using works differently. You find its documentation here.

upload_to參數用於模型。ImageField。的形式。使用的ImageField不同。你可以在這里找到它的文檔。

#2


0  

As Johannes Charra said - forms.ImageField doesn't have param upload_to. I solved my problem by adding a clean_file method in which I changed the InMemoryUploadedFile name attribute.

正如約翰內斯·查拉所說——表格。ImageField沒有param upload_to。我通過添加一個clean_file方法解決了這個問題,其中我更改了InMemoryUploadedFile name屬性。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2013/09/04/dde830d4137ed8f531b4372eee736c7a.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com