我正在 pythonanywhere.com 中开发 web2py - 模型 - db_testing.py
下面的代码运行成功:
# -*- coding: utf-8 -*-
db = DAL('sqlite://storage.sqlite')
db.define_table('registration',
Field('firstname', requires=IS_NOT_EMPTY(error_message='Should not left blank')),
Field('lastname', requires=IS_NOT_EMPTY()),
Field('gender', requires=IS_IN_SET(['Male', 'Female'])),
Field('birthday', 'date'),
Field('email', requires = IS_EMAIL(error_message='invalid email!')),
Field('salary', 'integer'),
Field('seniority', 'integer')
)
但是,第一个字段 'firstname' 只能防止表单填写不留空。它无法验证输入是在 az 还是 AZ。
最后一个字段'seniority'可以保证填表必须是0-9,但不能阻止填表不留空。
如何设置这两个要求(IS_NOT_EMPTY 和 error_message 并确保输入是字符串/整数)?
有什么想法吗?