gpt4 book ai didi

python - 属性错误 : module 'django.forms.forms has no attribute ' ModelForm'

转载 作者:行者123 更新时间:2023-12-05 02:11:57 25 4
gpt4 key购买 nike

from django.forms import forms
from .models import StudentModel


class StudentForm(forms.ModelForm):
name = forms.CharField(label='Name', max_length=200, widget=forms.TextInput(attrs={
'class': 'form-control',
'placeholder' : 'Enter Name Here '
}))

age = forms.CharField(max_length=200, required=False, widget=forms.TextInput(attrs={
'class': 'form-control',
'placeholder': 'Age '
}))

address = forms.CharField(max_length=200, required=False, widget=forms.TextInput(attrs={
'class': 'form-control',
'placeholder': 'Address '
}))

email = forms.CharField(max_length=200, required=False, widget=forms.TextInput(attrs={
'class': 'form-control',
'placeholder': 'Enter Email Here '
}))

pin = forms.CharField(max_length=200, required=False, widget=forms.TextInput(attrs={
'class': 'form-control',
'placeholder': 'Enter Pin Here '
}))

mob = forms.CharField(max_length=200, required=False, widget=forms.TextInput(attrs={
'class': 'form-control',
'placeholder': 'Enter Mobile Number Here '
}))

class Meta():
model = StudentModel
fields = ['name', 'age', 'address', 'email', 'pin', 'mob']

最佳答案

当我收到“AttributeError: module 'django.forms.forms' has no attribute 'ModelForm'”时,我检查了我的 Django 模块并更改了下面的字段。当我第一次检查我的模块时,它是这样的:

from django.forms import forms

#then I change as below field:

from django import forms

=> forms.ModelForm问题解决了

关于python - 属性错误 : module 'django.forms.forms has no attribute ' ModelForm',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56785003/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com