# Using split in my flask wtf form

**URL:** <https://discuss.python.org/t/using-split-in-my-flask-wtf-form/55499>\
**Category:** Python Help\
**Created:** [June 11, 2024, 4:10pm UTC](https://discuss.python.org/t/using-split-in-my-flask-wtf-form/55499 "2024-06-11T16:10:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![robina80](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/robina80/32/20142_2.png) [@robina80](https://discuss.python.org/u/robina80)\
**Post date:** [June 11, 2024, 4:10pm UTC](https://discuss.python.org/t/using-split-in-my-flask-wtf-form/55499/1 "2024-06-11T16:10:16Z")

</div>

hi all,

im trying to put a split command in my code like so

```python
class PasswordForm(FlaskForm):
    un = StringField('Username', [InputRequired(message='please enter your Username')])
    name = un.split(".")
    op = PasswordField('Current Password', [InputRequired(message='please enter your current password')])
    np = PasswordField('New Password', [InputRequired(message='please enter your new password'), EqualTo('cnp', message='must match confirm new password'), Length(min=12), Regexp('.*[a-z]', message='must contain one lower case'), Regexp('.*[A-Z]', message='must contain one upper case'), Regexp('.*[0-9]', message='must contain one number'), Regexp('.*[\¬\!\"\£\$\%\^\&\*\(\)\_\+\`\-\=\{\}\:\@\~\<\>\?\[\]\;\'\#\,\.\/\\\|]', message='must contain one special character')])
    cnp = PasswordField('Confirm New Password')

```

but i get this error when i run it in cmd

```python
C:\python>python password.py
C:\python\password.py:14: SyntaxWarning: invalid escape sequence '\!'
  np = PasswordField('New Password', [InputRequired(message='please enter your new password'), EqualTo('cnp', message='must match confirm new password'), Length(min=12), Regexp('.*[a-z]', message='must contain one lower case'), Regexp('.*[A-Z]', message='must contain one upper case'), Regexp('.*[0-9]', message='must contain one number'), Regexp('.*[\¬\!\"\£\$\%\^\&\*\(\)\_\+\`\-\=\{\}\:\@\~\<\>\?\[\]\;\'\#\,\.\/\\\|]', message='must contain one special character')])
Traceback (most recent call last):
  File "C:\python\password.py", line 10, in <module>
    class PasswordForm(FlaskForm):
  File "C:\python\password.py", line 12, in PasswordForm
    name = un.split(".")
           ^^^^^^^^
AttributeError: 'UnboundField' object has no attribute 'split'

```

any help will be greatly appreciated

thanks,  
rob

---

<div class="post-metadata">

**Author:** ![MRAB](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@MRAB](https://discuss.python.org/u/MRAB)\
**Post date:** [June 11, 2024, 4:25pm UTC](https://discuss.python.org/t/using-split-in-my-flask-wtf-form/55499/2 "2024-06-11T16:25:51Z")

</div>

Look at the previous line in the code. You’re making `un` a `StringField` object. `str` objects have a `split` method, but `StringField` objects don’t.

---

<div class="post-metadata">

**Author:** ![robina80](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/robina80/32/20142_2.png) [@robina80](https://discuss.python.org/u/robina80)\
**Post date:** [June 11, 2024, 4:41pm UTC](https://discuss.python.org/t/using-split-in-my-flask-wtf-form/55499/3 "2024-06-11T16:41:34Z")

</div>

so basically i cant use it with the un variable as its a stringfield?

sorry as im fairly new to python

---

<div class="post-metadata">

**Author:** ![davidism](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/davidism/32/3295_2.png) [@davidism](https://discuss.python.org/u/davidism)\
**Post date:** [June 11, 2024, 4:50pm UTC](https://discuss.python.org/t/using-split-in-my-flask-wtf-form/55499/4 "2024-06-11T16:50:31Z")

</div>

`form.un` is the field object. `form.un.data` is the string, which you would access after creating an instance of your form to process submitted data.

---

<div class="post-metadata">

**Author:** ![robina80](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/robina80/32/20142_2.png) [@robina80](https://discuss.python.org/u/robina80)\
**Post date:** [June 11, 2024, 5:04pm UTC](https://discuss.python.org/t/using-split-in-my-flask-wtf-form/55499/5 "2024-06-11T17:04:06Z")

</div>

tried

name = form.un.data.split(“.”)  
name = form.un.split(“.”)

same error saying form is not defined

---

<div class="post-metadata">

**Author:** ![davidism](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/davidism/32/3295_2.png) [@davidism](https://discuss.python.org/u/davidism)\
**Post date:** [June 11, 2024, 5:13pm UTC](https://discuss.python.org/t/using-split-in-my-flask-wtf-form/55499/6 "2024-06-11T17:13:01Z")

</div>

`form = MyForm()`

It sounds like you may not be familiar with WTForms and Flask-WTF. Manipulating data is done after creating an instance of the form, not when defining the class and fields. You should start with their docs first: [Crash Course — WTForms Documentation (3.1.x)](https://wtforms.readthedocs.io/en/3.1.x/crash_course/) and [Quickstart — Flask-WTF Documentation (1.2.x)](https://flask-wtf.readthedocs.io/en/1.2.x/quickstart/)
