我是 web2py 的新手,我正在为此苦苦挣扎
我正在尝试创建一个注册和登录的东西。在模型中,我有以下代码为新用户创建表格
usersdb = DAL('postgres://postgres:postgres@localhost/'+ request.vars['school'], migrate=True)
auth = Auth(usersdb, hmac_key=Auth.get_or_create_key())
usersdb.define_table(
'users',
Field('first_name', length=128, default=''),
Field('last_name', length=128, default=''),
Field('email', length=128, default='', unique=True),
Field('address', length=256, default=''),
Field('postcode', length=128, default=''),
Field('city', length=128, default=''),
Field('password', 'password', length=512, readable=False, label='Password'),
Field('registration_key', length=512, writable=False, readable=False, default=''),
Field('reset_password_key', length=512, writable=False, readable=False, default=''),
Field('registration_id', length=512, writable=False, readable=False, default=''),
format='%(first_name)s %(last_name)s')
所以现在在控制器中我有以下代码:
usersdb = DAL('postgres://postgres:postgres@localhost/'+ request.vars['school'], migrate=True)
auth = Auth(usersdb, hmac_key=Auth.get_or_create_key())
auth.settings.registration_requires_approval = True
form = SQLFORM(usersdb.users)
if form.process(session=None, formname='test').accepted:
response.flash = 'form accepted'
elif form.errors:
response.flash = 'form has errors'
else:
response.flash = 'please fill the form'
# Note: no form instance is passed to the view
#set sample validator (do not allow empty nor duplicate names)
return dict(form=form,config=config)
该错误记录在 SQLFORM (usersdb.users) 中。“用户”
我不知道这些东西实际上是如何工作的(将数据库连接到控制器)。我正在破解 smb 编写的代码。别的。
感谢您的任何建议或简短的解释。
再见