Re: KeyError, Submit Empty Field and Form Validation

2007-11-13 Thread Gloria W

This was an excellent response, and helped me immediately. Thank you.
~G~


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: KeyError, Submit Empty Field and Form Validation

2007-11-02 Thread Karen Tracey
On 11/2/07, crybaby <[EMAIL PROTECTED]> wrote:
>
>
> I have @login_required decorator for the view function that handles
> this form and I am already logged in.
> I commented out the "def clean" from the form and when I submit the
> form field reason without a value, I get this error:
>
> Exception Type: ValueError
> Exception Value:The view
> django.contrib.auth.decorators._checklogin
> didn't return an HttpResponse object.


Well, what does your view code do in the case where form.is_valid() returns
False?  Based on the error it would seem it returns None  (_checklogin is
named simply because you've wrapped your function in it -- it's returning
whatever your view function returned).  Your view still needs to return an
HttpResponse object even when the form validation fails.

Karen

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: KeyError, Submit Empty Field and Form Validation

2007-11-02 Thread crybaby

I have @login_required decorator for the view function that handles
this form and I am already logged in.
I commented out the "def clean" from the form and when I submit the
form field reason without a value, I get this error:

Exception Type: ValueError
Exception Value:The view django.contrib.auth.decorators._checklogin
didn't return an HttpResponse object.

C:\python\lib\site-packages\django\core\handlers\base.py in
_real_get_response

  91.
  92. # Complain if the view returned None (a common error).
  93. if response is None:
  94. try:
  95. view_name = callback.func_name # If it's a function
  96. except AttributeError:
  97. view_name = callback.__class__.__name__ + '.__call__' # If it's
a class

  98. raise ValueError, "The view %s.%s didn't return an HttpResponse
object." % (callback.__module__, view_name) ...

  99.
 100. return response
 101. except http.Http404, e:
 102. if settings.DEBUG:
 103. from django.views import debug
 104. return debug.technical_404_response(request, e)



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: KeyError, Submit Empty Field and Form Validation

2007-11-02 Thread Karen Tracey
On 11/2/07, crybaby <[EMAIL PROTECTED]> wrote:
>
>
> I have a form and trying to do validation.  When I submit a form
> without any values into the field, "reason", I get this error.
>
> Exception Type: KeyError
> Exception Value:'reason'
>
> at this line of ReasonForm:
>
> if(self.cleaned_data['reason']==''):
>
> here is my ReasonForm:
> class ReasonForm(forms.Form):
>
> reason = forms.CharField(max_length=250)
>
> def clean(self):
> if(self.cleaned_data['reason']==''):
> raise forms.ValidationError('Invalid Reason, please enter
> it.')
> return self.cleaned_data
>


The default field validation for a CharField will raise a validation error
if the field is required (which yours is, since you have not overridden the
default required=True) but empty.  When that happens, the field is removed
from cleaned_data.  So, by the time your form's clean() is run (after the
fields have been individually cleaned), 'reason' has already been flagged as
an error and is no longer in cleaned_data.  In short -- you don't need to be
checking for this, as it's already being done by default.

Karen

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---