我在以下代码中收到错误module 'django.forms.forms' has no attribute 'HiddenInput'
:
from django.forms import ModelForm, forms
from comments.models import Comment
class CommentForm(ModelForm):
class Meta:
model = Comment
fields = ['video', 'text']
widgets = {'video': forms.HiddenInput(),
'text': forms.TextArea()}
有谁知道是什么原因造成的?我在文档中进行了查找,并且HiddenInput()应该有效(https://docs.djangoproject.com/en/2.0/ref/forms/widgets/)。
最佳答案
您的导入不正确,请将导入更改为此:
from django import forms
并更新表单的基类:
class CommentForm(forms.ModelForm):
class Meta:
model = Comment
fields = ['video', 'text']
widgets = {'video': forms.HiddenInput(),
'text': forms.Textarea()}
关于python - Django没有属性“HiddenInput”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49809879/