django - My form instance is never valid -


i'm making social network in django , i've trouble user creation form. here's code:


views.py

def register(request):     if request.method == 'post':         form = userprofileform(request.post) #         if form.is_valid():             u = userprofile.objects.create(first_name = form.cleaned_data['first_name'],...)             u.set_password(u.password)             u.save()             return httpresponseredirect(...)         else:             return http404     else:         form = userprofileform()      return render_to_response(...,                              {'form': form},                              context_instance=requestcontext(request)) 

forms.py

 class userprofileform(modelform):           first_name = forms.charfield(help_text="por favor, introduzca su nombre",     required=true) ...  class meta:     model = userprofile     fields = ['first_name',...]  def __init__(self, request=none, *args, **kwargs):     self.user = kwargs.pop('user', none)     super(userprofileform, self).__init__(*args, **kwargs)   def validate_user(self):     first_name_length = len(self.cleaned_data['first_name'])     ...     if not first_name_length > 0:         raise validationerror("por favor, introduzca nombre valido")     ... 

models.py

class userprofile(models.model):     first_name = models.charfield(max_length=50, blank=true)... 

and i'm using templates form.as_p, form instance never valid. doing wrong? can me?

look @ signature of form:

def __init__(self, request=none, *args, **kwargs) 

and @ how instantiate it:

form = userprofileform(request.post) 

so, you're passing request.post request parameter.

you should avoid changing signature of subclass this. in particular in case not using or passing request @ all. if need this, should same user value kwargs (but again you're not using or passing either, don't know why you're bothering it.)


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -