Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python web2py-如何将field2的值设置为field1的值_Python_Web2py_Default Value - Fatal编程技术网

Python web2py-如何将field2的值设置为field1的值

Python web2py-如何将field2的值设置为field1的值,python,web2py,default-value,Python,Web2py,Default Value,我是web2py的新手,我正在尝试向auth_user添加额外字段,我正在尝试将默认值“mentor”设置为为为“referer”输入的值,如下面的代码所示,但它不起作用。创建记录时不追加任何数据。“导师”可以在稍后阶段更改,但默认设置为“推荐人”。我做错了什么?请给我一些建议 from gluon.tools import Auth, Crud, Service, PluginManager, prettydate auth = Auth(db) crud, service, plugins

我是web2py的新手,我正在尝试向auth_user添加额外字段,我正在尝试将默认值“mentor”设置为为为“referer”输入的值,如下面的代码所示,但它不起作用。创建记录时不追加任何数据。“导师”可以在稍后阶段更改,但默认设置为“推荐人”。我做错了什么?请给我一些建议

from gluon.tools import Auth, Crud, Service, PluginManager, prettydate
auth = Auth(db)
crud, service, plugins = Crud(db), Service(), PluginManager()
auth.settings.extra_fields['auth_user']=[
   Field('gender', requires=IS_IN_SET(['Female', 'Male'])),
   Field('birthday', type='date'),
   Field('country'),
   Field('city'),
   Field('referrer', default = 'admin'),
   Field('mentor', default=request.post_vars.referrer)]

你做这件事可能会更走运

def get_default_mentor():
    return request.post_vars.referrer

根据我的经验,当默认值可以更改时,最好将默认字段设置为获取默认值的函数

见:
default=get_default_mentor()