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

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -