简体   繁体   English

django user_passes_test装饰器is_superuser

[英]django user_passes_test decorator is_superuser

Initially i was restricting the permission for all user with the help of is_superuser flag,and i used @user_passes_test(lambda u: u.is_superuser) decorator.Now i am not using is_superuser flag and instead i created a field in UserProfile model called is_admin_user and allowing the permission depend on the flag in UserProfile model. 最初我是在is_superuser标志的帮助下限制所有用户的权限,然后我使用@user_passes_test(lambda u: u.is_superuser)装饰器。现在我不使用is_superuser标志,而是在UserProfile模型中创建了一个名为is_admin_user的字段,允许权限取决于UserProfile模型中的标志。

If is_admin_user flag is set,he can access the application settings page,otherwise they can't access the settings page.While creating profile using is_admin_user flag,the default django is_superuser flag is set to false.Since i am using the decorator i am not able to access the settings page.If i click settings page it redirect to login page. 如果设置了is_admin_user标志,则他可以访问应用程序设置页面,否则将无法访问设置页面。使用is_admin_user标志创建配置文件时,默认的django is_superuser标志设置为false。由于我使用的是装饰器,因此我没有能够访问设置页面。如果我单击设置页面,它将重定向到登录页面。

1.Is it possible to create any other custom thing for is_admin_user. 1.是否可以为is_admin_user创建任何其他自定义内容。

2.If i comment this line @user_passes_test(lambda u: u.is_superuser) ,able to move to settings page. 2.如果我在@user_passes_test(lambda u: u.is_superuser)这行评论,可以移动到设置页面。

Need suggestion. 需要建议。

Use something like 使用类似

@user_passes_test(lambda u: u.userprofile.is_admin_user)

You may need to change userprofile to your profile related_name 您可能需要更改userprofile到您的个人资料related_name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM