[Django] User Rights Learning Series design ideas of own rights management system

Source: Internet
Author: User

If you are reading this article, check out the first two chapters of this series for permission operation issues!

Http://www.cnblogs.com/CQ-LQJ/p/5609690.html and Http://www.cnblogs.com/CQ-LQJ/p/5604331.html

Now get to the point, this article is about the own rights management system design ideas, self-owned Rights management system is to abandon the background management interface Django, based on their own written rights management bounded by the user Rights Management!

First: (Self-designed permission system interface, code will be written in subsequent articles)

The Rights management interface is mainly to add and remove permissions, to view official documents can be known permission has three fields, content_type_id (permission type), codename (permission name), name (permission description)

View, the name of the right to display the Chinese, Django background comes with English, such as:

Of course, the Chinese is my own added, the advantage of using Chinese is also one, is can be used in the background using regular expressions to filter out only the Chinese permission, so that you can not show the English permission to make users understand, the Chinese regular is [\u4e00-\u9fa5].

Background View query Chinese permission code is as follows:

= Permission.objects. Get (Codename__iregex=u'[\u4e00-\u9fa5]') Print C # matches Chinese permissions (all queries) Permission.objects.filter (Codename__iregex=u'[\u4e00-\u9fa5]'). VALUES ()

The user management interface is to add users and assign permissions to users, such as:

Perhaps someone will ask, how to implement the permission control of a Web page or operation after the user rights are configured well?

In fact, the code and the Django official website almost, in the template to verify the permissions code as follows:

{% if perms.auth. Business Development%}<Pclass= "Text-center"><ahref= "{% url ' keywork '%}">Business development</a></P>{% Else%}<Pclass= "Text-center"><ahref= "Javascript:alert (' no permission, please contact admin! ')">Business development</a></P>
{% ENDIF%}

The check permissions in view are as follows


U = User.objects.get (username= ' account ') u.has_perm (u "auth.\u4e1a\u52a1\u53d1\u5c55")

In this case, you need to first use B = List (User.objects.get (username= ' account '). Get_all_permissions ()) View the code displayed in the Chinese counterpart Pyhton for the permission

The specific production process, will be in the follow-up of the article slowly, in order to restore a development of the right system of the real process, rather than just paste a large code up (PS: It is this before) ...

[Django] User Rights Learning Series design ideas of own rights management system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.