Reputation: 2668
I'm trying to edit the group membership for a user, I have in my controller:
def change_membership():
if request.vars.id:
row = db(db.auth_membership.user_id == request.vars.id).select()
id = row[0].id
form = SQLFORM(db.auth_membership,
id,
fields=['group_id'],
_action=URL()
)
if form.process().accepted:
...redirect back to user list
if form.errors:
response.flash = 'form has errors'
return dict(form=form)
But It doesn't work, I get a : list index out of range
I know that only get one row, but I don't understand why its seems empty..
Thanks in advance
Christian
Upvotes: 2
Views: 2292
Reputation: 2668
Excellent!
Thanks a lot Anthony and Massimo.
It´s save my day, now all is working using request.get_vars.id instead of request.vars.id
Reference:
2012/8/22 Anthony wrote: Yes. Note, web2py stores GET variables in request.get_vars and POST variables in request.post_vars. It stores both GET and POST vars in request.vars. If both get_vars and post_vars have variables with the same name, it puts their values in a list within request.vars. Just change your code to use request.get_vars.id instead of request.vars.id.
2012/8/22 Massimo Di Pierro wrote: You have two id fields. One in request.get_vars.id (from the url) and one in request.post_vars.id (from the form submission).
Upvotes: 2