Skip to content

Commit bb3679d

Browse files
committed
Improve the README.
1 parent bec8ee8 commit bb3679d

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ pip install django-casbin
1212

1313
## Simple Example
1414

15+
This repo is just a working Django app that shows the usage of django-casbin. To use it in your existing Django app, you need:
16+
1517
- Add the middleware to your Django app's ``settings.py``:
1618

1719
```python
@@ -27,18 +29,19 @@ MIDDLEWARE = [
2729
]
2830
```
2931

30-
- In ``casbin_middleware/middleware.py``:
32+
- Copy ``casbin_middleware`` folder to your Django's top folder, modify ``casbin_middleware/middleware.py`` if you need:
3133

3234
```python
3335
import casbin
3436

3537
def __init__(self, get_response):
3638
self.get_response = get_response
37-
# load the casbin model and policy from files, database is also supported.
39+
# load the casbin model and policy from files.
40+
# change the 2nd arg to use a database.
3841
self.enforcer = casbin.Enforcer("casbin_middleware/authz_model.conf", "casbin_middleware/authz_policy.csv")
3942

4043
def check_permission(self, request):
41-
# check the permission.
44+
# change the user, path, method as you need.
4245
user = request.user.username
4346
if request.user.is_anonymous:
4447
user = 'anonymous'
@@ -47,6 +50,16 @@ import casbin
4750
return self.enforcer.enforce(user, path, method)
4851
```
4952

53+
- The default policy ``authz_policy.csv`` is:
54+
55+
```csv
56+
p, anonymous, /, GET
57+
p, admin, *, *
58+
g, alice, admin
59+
```
60+
61+
It means ``anonymous`` user can only access homepage ``/``. Admin users like alice can access any pages. Currently all accesses are regarded as ``anonymous``. Add your authentication to let a user log in.
62+
5063
## Documentation
5164

5265
The authorization determines a request based on ``{subject, object, action}``, which means what ``subject`` can perform what ``action`` on what ``object``. In this plugin, the meanings are:

0 commit comments

Comments
 (0)