accessing auth_user username

30 views
Skip to first unread message

Jaimee S

unread,
Oct 13, 2016, 9:28:47 PM10/13/16
to web2py-users
Hello All,

Im new to web2py and I can't seem to figure out how to access the usernames of the registered users. I added username to the default login and it renders just fine. In my controller I've tried various methods such as:


def xx():
item = db(db.auth_user).select(db.auth_user.username.ALL)
return locals()

def...:
item = db().select(db.auth_user.username.ALL)
return...

def...:
item = # both previous func with periods instead of _

@auth.requires_login()
def...:
item = # prev logic

In html I've tried:

{{=item}}

{{for ite in item:}}
<ul><li>{{=ite}}</li></ul>
{{pass}}

{{for...:}}
<ul....>{{=ite.username}}</....>
{{pass}}

# also tried same methods with table tags


My ticket error:
Name 'html_variable' is not defined

My plan is as follows:
Display all users on page as ul or td
Create css flex box and display each user by username
Display each user by image
Etc

Thanks for reading!

Also, this was posted from my phone which is why I used pseud code

Anthony

unread,
Oct 13, 2016, 9:46:40 PM10/13/16
to web2py-users
On Thursday, October 13, 2016 at 9:28:47 PM UTC-4, Jaimee S wrote:
Hello All,

Im new to web2py and I can't seem to figure out how to access the usernames of the registered users. I added username to the default login and it renders just fine. In my controller I've tried various methods such as:


def xx():
 item = db(db.auth_user).select(db.auth_user.username.ALL)

No, it is just .select(db.auth_user.username). But that assumes you only want the username field and no other fields. If you want all fields, then it is .select(db.auth_user.ALL). But that isn't necessary either, because as long as there is a query inside db(), you can leave the .select() empty, and you will get all fields by default -- so, just do:

all_users = db(db.auth_user).select()

This is all in the documentation.

Anthony

Jaimee S

unread,
Oct 14, 2016, 4:09:50 AM10/14/16
to web2py-users
Oh I see, I misunderstood how to access Auth. You're right, I'll need to read more of the documentation. BTW your answer worked, thanks!

Pierre

unread,
Oct 14, 2016, 5:22:18 AM10/14/16
to web2py-users
Hi,

Using iterselect  is there a better way to collect usernames than to include auth_user in join queries. Is there an equivalent of rows.render() compatible with iterselect ?


Reply all
Reply to author
Forward
0 new messages