Saturday, February 12, 2011

How to access a form attribute? (For HTML sanitization)

Hi, I want to sanitize the HTML my user inputs in a form. I'm getting
an error that says "'QuestionForm' object has no attribute
'explanation'" Even though I think it should have. I must be doing
something wrong, but I'm not very familiar with form handling.

My form is defined as:

class QuestionForm(ModelForm):
explanation = forms.CharField(required=False,
widget=forms.Textarea(attrs={'name': 'editor1', 'style': 'height:
200px;' } ))

class Meta:
model = Question
exclude = ('relatedProject', 'answered')


In my view I try to access the "explanation" field like this:

form = QuestionForm(request.POST, instance = question) # A form
bound to the POST data

if form.is_valid(): # All validation rules pass
form.explanation = sanitizeHtml(form.explanation)

This gives the error "QuestionForm' object has no attribute
'explanation'"

Thanks for your help

--
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 django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate