Reputation: 43
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']
Upvotes: 3
Views: 14216
Reputation: 373
I encountered the same issue when attempting to execute the "makemigrations" command.
Upon reviewing the forms.py module, it has been identified that the letter 'f' should be capitalized in ModelForm.
Upon making the adjustments, the "makemigrations" command proceeded without any disruptions.
Upvotes: 0
Reputation: 1
from django.forms import ModelForm
class SampleForm(forms.ModelForm):
class Meta:
model = SampleModel
fields = ['name']
Change the from django.forms import forms
to from django.forms import ModelForm
and this should work.
Upvotes: 0
Reputation: 632
When I got the "AttributeError: module 'django.forms.forms' has no attribute 'ModelForm' ", I checked my django modules and changed the field below. When I first checked my module it was like this:
from django.forms import forms
#then I change as below field:
from django import forms
=> forms.ModelForm problem solved
Upvotes: 3
Reputation: 8566
It should be from django.forms import ModelForm
then you can use class StudentForm(ModelForm):
or from django import forms
.
Upvotes: 3