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']
-
Can you please elaborate on what you have tried so far?Mike_H– Mike_H2019-06-27 07:03:09 +00:00Commented Jun 27, 2019 at 7:03
4 Answers
It should be from django.forms import ModelForm then you can use class StudentForm(ModelForm): or from django import forms.
2 Comments
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
Comments
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.

