Django - 限制访问超级用户的URL [英] Django - limiting url access to superusers

查看:171
本文介绍了Django - 限制访问超级用户的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的urlconf中,我有:

  url(r'^ sssssh /(.*)',staff_only_app.site .root),

我想做的是限制对这个应用程序的访问权限给超级用户。
我试过这个:

  url(r'^ sssssh /(.*)',user_passes_test(staff_only_app.site .root,lambda u:u.is_superuser)),

但是它抱怨装饰只需要1个参数我给了两个。



我正在考虑通过functools.partial来调节装饰器,但认为我可能会缺少一些更明显的解决方案。

解决方案

非常晚的回复!



我认为这只是一个快速而肮脏的语法挂断:

  url(r'^ sssssh /(.*)',user_passes_test(lambda u:u.is_superuser)(staff_only_app.site.root) ,

^我认为这是将参数传递给装饰器的奇怪但正确的语法。 p>

但是,第二个想法,你只能装饰视图功能,而不是整个站点。


In my urlconf, i have:

url(r'^sssssh/(.*)', staff_only_app.site.root),

What I'd like to do is limiting any access to this application to superusers. I tried this:

url(r'^sssssh/(.*)', user_passes_test(staff_only_app.site.root, lambda u: u.is_superuser)),

But it complains that decorate takes exactly 1 argument, and I gave two.

I'm thinking about currying the decorator via functools.partial, but thought I may be missing some more obvious solution.

解决方案

Very late reply!...

I think it's just a quick and dirty syntax hangup:

url(r'^sssssh/(.*)', user_passes_test(lambda u: u.is_superuser)(staff_only_app.site.root),

^I think this is the strange but correct syntax for passing an argument to a decorator.

But on 2nd thought, you can only decorate view functions, not entire sites.

这篇关于Django - 限制访问超级用户的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆