【发布时间】:2020-11-16 14:17:01
【问题描述】:
我正在尝试使用Otree 对主题可以在表单字段中使用的最少字符数进行限制。我希望如果受试者输入的名称长度少于 4 个字符,应用程序会向他们显示一个错误,说明他们必须写一个更长的单词。
我正在使用len,但出现以下错误:
'NoneType' has no len()
谁能帮我找出代码中的问题并帮我修复它?
这是我的 pages.py 代码。
class Consentimiento(Page):
form_model = 'player'
form_fields = ['consentimiento', 'consentimienton',]
def consentimiento_error_message(self, value):
print('El nombre es', value)
if len(self.player.consentimiento)) < Constants.number:
return 'Por favor en el campo de nombre debe poner mínimo 4 letras'
这是我的 models.py 代码
consentimienton = models.StringField( max_length=50 )
【问题讨论】:
-
这是什么? self.player.consentimiento 另外,consentimiento 和 consentimienton 很容易混合
-
self.player.consentimiento 是一个空的字符串字段,人们在其中输入他们的姓名。
-
你确定它是stringField类型的吗?尝试打印出
self.player.consentimiento的类型,然后检查是否是len()的兼容类型 -
是的,我在models.py中定义了