Google App Engine: extract just username from db.UserProperty
I was 开发者_StackOverflow社区wondering what is the best way to extract just the username (the portion before @ symbol) from db.UserProperty. Perhaps there is a built-in method that i don't know? the nickname method is returning full username.
From the Google appengine code:
A nickname is a human-readable string which uniquely identifies a Google user, akin to a username. It will be an email address for some users, but not all.
So it maybe the username or the email depending on the account.
email()
Returns the email address of the user. If you use OpenID, you should not rely on this email address to be correct. Applications should use nickname for displayable names.
There is no built-in method to do that. But can you do something like this
from google.appengine.api import users
user =user=users.get_current_user()
email = user.email()
username = str(email).split('@')[0]
精彩评论