问题描述
在中,有没有办法找出是管理员?
虽然显示当前用户是否是管理员,我想知道是否有办法发现给定的 User
对象是否适用于管理员或者不是(例如假设 User.is_admin()
函数)。
感谢您的阅读。
Brian
不幸的是,模型不包含任何有关用户是否为管理员的信息。
如果你的管理员列表很少变化,那么你可以编写你自己的 is_admin()
函数来检查值对应于您的某个管理员'账户。例如:
ADMIN_USER_IDS = ['id1','id2',...]#手动填充列表
def is_admin(user):
返回ADMIN_USER_IDS中的user.user_id()
In GAE, is there a way to find out if a User is an administrator?
While the is_current_user_admin()
reveals whether the current user is an administrator, I'd like to know if there's a way to discover if a given User
object is for an administrator or not (e.g. a hypothetical User.is_admin()
function).
Thank you for reading.
Brian
Unfortunately, the User model does not contain any information about whether the user is an administrator or not.
If your list of administrators changes infrequently, then you could write your own is_admin()
function which checks to see if the User.user_id()
value corresponds to one of your administrators' accounts. For example:
ADMIN_USER_IDS = ['id1', 'id2', ...] # manually populated list
def is_admin(user):
return user.user_id() in ADMIN_USER_IDS
这篇关于Google App Engine - 了解用户是否是管理员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!