Skip to main content
 首页 » 编程设计

python之Google App Engine django 模型表单不获取 BlobProperty

2025年05月04日10xxx_UU

我有以下模型:

class Image(db.Model): 
    auction = db.ReferenceProperty(Auction) 
    image = db.BlobProperty() 
    thumb = db.BlobProperty() 
    caption = db.StringProperty() 
    item_to_tag = db.StringProperty() 

和下面的形式:

class ImageForm(djangoforms.ModelForm): 
    class Meta: 
        model = Image 

当我调用 ImageForm() 时,只会创建非 Blob 字段,如下所示:

<tr><th><label for="id_auction">Auction:</label></th><td><select name="auction" id="id_auction"> 
<option value="" selected="selected">---------</option> 
<option value="ahRoYXJ0bWFuYXVjdGlvbmVlcmluZ3INCxIHQXVjdGlvbhgKDA">2010-06-19 11:00:00</option> 
</select></td></tr> 
<tr><th><label for="id_caption">Caption:</label></th><td><input type="text" name="caption" id="id_caption" /></td></tr> 
<tr><th><label for="id_item_to_tag">Item to tag:</label></th><td><input type="text" name="item_to_tag" id="id_item_to_tag" /></td></tr> 

我希望 Blob 字段也包含在表单中(作为文件输入)。我做错了什么?

请您参考如下方法:

我认为我的问题取决于 Django 不支持 blob,因此在生成 Django 表单时会忽略 BlobProperty。