Django的规则注册表
django-rules-light的Python项目详细描述
这是django规则的简单替代。核心区别在于 它使用可在运行时修改的注册表,而不是数据库 模型。
目标之一是使外部应用程序的开发人员能够制定规则,依赖于 同时允许项目重写规则。
示例your_app/rules_light_registry.py:
# Everybody can read a blog post (for now!):rules_light.registry['blog.post.read']=True# Require authentication to create a blog post, using a shortcut:rules_light.registry['blog.post.create']=rules_light.is_authenticateddefis_staff_or_mine(user,rule,obj):returnuser.is_stafforobj.author==user# But others shouldn't mess with my posts !rules_light.registry['blog.post.update']=is_staff_or_minerules_light.registry['blog.post.delete']=is_staff_or_mine
示例your_app/views.py:
@rules_light.class_decoratorclassPostDetailView(generic.DetailView):model=Post@rules_light.class_decoratorclassPostCreateView(generic.CreateView):model=Post@rules_light.class_decoratorclassPostUpdateView(generic.UpdateView):model=Post@rules_light.class_decoratorclassPostDeleteView(generic.DeleteView):model=Post
您可能需要阅读 更多。
要求
- Python2.7+(支持Python3)
- Django 1.8+
快速安装
- 安装模块:pip install django-rules-light,
- 添加到settings.INSTALLED_APPS:rules_light,
- 外接程序settings.MIDDLEWARE_CLASSES(或settings.MIDDLEWARE用于django 1.10+):rules_light.middleware.Middleware,
您可能需要阅读tutorial。
还有很多文档,从核心到工具,包括 调试、记录和测试安全性的指针。
贡献
使用tox命令运行测试。通过所有 测试有更多的机会被合并到中,有关详细信息,请参见community guidelines。
资源
你可以订阅邮件列表,提出问题,或只是被告知 包更新。