How to add fields url for nested output fields in flask restful

后端 未结 1 473
遥遥无期
遥遥无期 2020-12-22 06:55

I am having difficulty over generating api endpoint urls in nested output fields using [Flask-RESTful][1].

I found that fields.Url(\'my_endpoint\', absolute=Tr

1条回答
  •  礼貌的吻别
    2020-12-22 07:15

    The problem was fields.Url needs a required endpoint parameter, In this case its username.

    The parameter username is available to user_fields with the returned user object, but the role object user.role does not contain username attribute.

    So I assigned 'usernameattribute touser.role` object before returning it.

    user = get_user(username) #Get user object from db
    user.role.username = user.username
    return user
    

    0 讨论(0)
提交回复
热议问题