python - Strip spaces from Django form -
i getting form through post request:
form = reportdataform2(req.post)
i trying strip spaces fields by:
for element in form: form[element] = form[element].strip()
but not seem anything.
i tried stripping @ point receiving data:
id = form.cleaned_data['id'].strip()
not working either.
i new django don't know how forms treated.
how this: extend charfield class, create own field, , use anytime want have stripped field?
class strippedcharfield(charfield): """newforms charfield strips trailing , leading spaces.""" def clean(self, value): if value not none: value = value.strip() return super(strippedcharfield, self).clean(value)
there's been long discussion on whether form data stripping should handled django or not. discussion resurrected actual thread started 7 years ago
i haven't tested code above myself. the solution pulled forum discussion
Comments
Post a Comment