django ModelForm: error name 'self' is not defined

52 views
Skip to first unread message

JAI PRAKASH SINGH

unread,
Dec 9, 2014, 1:17:57 AM12/9/14
to django...@googlegroups.com
hello all, 


I am trying to make a registration form using User model so  i am using ModelForm 

as I am using bootstrap template i need to add some atribute like class placeholder 

so i am using widget, am facing a problem , i searchd a lot but unable to find the solution 

please help 

my code is under 


####################################################################

error :- name 'self' is not defined
on borwser 

######################################################################3

forms.py 


class RegistrationForm(ModelForm):

class Meta:
model = User
fields = [ 'username', 'password', 'email' ]

def __init__(self, *args, **kwargs): 
   super(RegistrationForm, self).__init__(*args, **kwargs)

   self.fields['username'].widget = forms.TextInput(attrs={"placeholder" : "First Name", 
            "name" : "first_name"})

   self.fields['email'].widget = forms.TextInput(attrs={"placeholder" : "Email Address", 
            "name" : "email"})

        self.fields['password'].widget = forms.PasswordInput(attrs={
        "placeholder" : "Password", "name" : "password", "class" : "form-control input-sm"})

Daniel Roseman

unread,
Dec 9, 2014, 4:18:34 AM12/9/14
to django...@googlegroups.com
Make sure the last line is indented to the same level as the others. 
--
DR.
Reply all
Reply to author
Forward
0 new messages