如何不当前渲染django图像字段并清除内容? [英] How to not render django image field currently and clear stuff?
本文介绍了如何不当前渲染django图像字段并清除内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我看了以下SO问题,但是没有运气.我不知道,也许我听不懂答案.
I took a look at following SO question, but had no luck. I don't know, maybe I didn't understand the answers.
1)如何在Django中删除当前"标签和FileInput小部件的链接?
2) Django ModelForm ImageField
我的表单:
class SettingsForm(forms.ModelForm):
company_logo = forms.ImageField(label=_('Company Logo'),required=False, error_messages = {'invalid':_("Image files only")})
class Meta:
model = Settings
fields = ("company_logo")
....
我的模型:
class Settings(models.Model):
strg=CustomFileSystemStorage(strict_name='images/company_logo.png',save_format='PNG')
company_logo=models.ImageField(upload_to='images',blank=True,null=True,storage=strg)
.....
渲染后:
我从第一个链接中看到, models.ImageField
继承了 FileInput
并添加了额外的内容,但是我不知道如何克服这个问题?
I see from the first link, that the models.ImageField
inherits the FileInput
and adds the extra stuff, but I do not understand how to overcome this?
先谢谢了.
推荐答案
解决方案是:
class SettingsForm(forms.ModelForm):
company_logo = forms.ImageField(label=_('Company Logo'),required=False, error_messages = {'invalid':_("Image files only")}, widget=forms.FileInput)
class Meta:
model = Settings
fields = ("company_logo")
....
我添加了小部件 forms.FileInput
,以告知ImageField使用基本字段,而不是从 FileInput
继承的字段.
I added the widget forms.FileInput
, in order to tell the ImageField to use the basic field, not the one inherited from FileInput
.
这篇关于如何不当前渲染django图像字段并清除内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文