3
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']

1
  • Can you please elaborate on what you have tried so far? Commented Jun 27, 2019 at 7:03

4 Answers 4

3

It should be from django.forms import ModelForm then you can use class StudentForm(ModelForm): or from django import forms.

Sign up to request clarification or add additional context in comments.

2 Comments

okay @ujwalzare, you got it, right? Any other problem regarding to your question?
You're welcome @ujwalzare, if this helpful make this answer as accepted one which will help someone when they get this error again. Thank you!
3

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

0
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.

Comments

0

I encountered the same issue when attempting to execute the "makemigrations" command.

enter image description here

Upon reviewing the forms.py module, it has been identified that the letter 'f' should be capitalized in ModelForm.

enter image description here

Upon making the adjustments, the "makemigrations" command proceeded without any disruptions.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.