Z
Z
zedzew2015-03-24 01:44:00
Flask
zedzew, 2015-03-24 01:44:00

What is the problem with TypeError: object of type 'int' has no len()?

forms.py

class MoneyMarketForm(Form):
    want = SelectField('State', choices=[('b', 'buy'), ('s', 'sell')])
    currency = SelectField('curency', choices=[('u','USD'),('e','EUR'),('r','RUB')])
    total = IntegerField('total', [validators.required(),validators.Length(0, 10000000)])
    course = IntegerField('course', [validators.required('Please enter your course'), validators.Length(0, 10000)])
    phone = IntegerField('phone', [validators.required(), validators.NumberRange(min=0, max=10)])
    city = SelectField('city' , choices=[('c1','city1'),('c2','city2'),('c3','city3'), ('c4', 'city4')])
    area = StringField('area', [validators.required(), validators.Length(max=200)])
    comment = StringField('cooment', [validators.required(), validators.Length(max=350)])
    relevant = IntegerField('relevant',[validators.required(), validators.Length(max=200)])#?
    #submint = SubmitField('Send')
    pub_date = DateTimeField('Posted Date (mm/dd/yyyy)', validators=[Required()], format='%m/%d/%Y')

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Deerenaros, 2015-03-24
@zedzew

total = IntegerField('total', [validators.required(),validators.Length(0, 10000000)])
course = IntegerField('course', [validators.required('Please enter your course'), validators.Length(0, 10000)])
#...
relevant = IntegerField('relevant',[validators.required(), validators.Length(max=200)])#?

In vain we add a validator. As int has no length, so he cannot digest it.

A
Anatoly Scherbakov, 2015-03-24
@Altaisoft

1. As already mentioned, a string should be used for the phone number. Otherwise, sooner or later you will have to use the + sign or, say, a number starting with 0 - and you have arrived.
2. The django-localflavor app includes a PhoneField field already in place .

Z
zedzew, 2015-03-24
@zedzew

phone = StringField('phone', validators = [validators.required(), Regexp('^\+?[0-9]{3}-?[0-9]{6,12}$')])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question