{"id":23402,"library":"casbin-django-orm-adapter","title":"Casbin Django ORM Adapter","description":"Django ORM adapter for PyCasbin, enabling Casbin permission management to store policies in Django models. Version 1.7.0 supports Python >=3.7 and Django 2.2+.","status":"active","version":"1.7.0","language":"python","source_language":"en","source_url":"https://github.com/pycasbin/casbin-django-orm-adapter","tags":["casbin","django-orm","authorization","adapter"],"install":[{"cmd":"pip install casbin-django-orm-adapter","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"required for ORM functionality","package":"django","optional":false},{"reason":"core authorization library","package":"casbin","optional":false}],"imports":[{"note":"Common mistake - Adapter is in the adapter submodule","wrong":"from casbin_django_orm_adapter import Adapter","symbol":"Adapter","correct":"from casbin_django_orm_adapter.adapter import Adapter"},{"note":"Model is in models submodule","wrong":"from casbin_django_orm_adapter import CasbinRule","symbol":"CasbinRule","correct":"from casbin_django_orm_adapter.models import CasbinRule"}],"quickstart":{"code":"import os\nimport django\nos.environ.setdefault('DJANGO_SETTINGS_MODULE', 'your_project.settings')\ndjango.setup()\n\nimport casbin\nfrom casbin_django_orm_adapter.adapter import Adapter\n\nadapter = Adapter()\ne = casbin.Enforcer('path/to/model.conf', adapter)\n\n# Check permission\nsub = 'alice'\nobj = 'data1'\nact = 'read'\nif e.enforce(sub, obj, act):\n    print('Access granted')\nelse:\n    print('Access denied')","lang":"python","description":"Initialize Casbin enforcer with Django ORM adapter. Ensure Django is configured and settings module is set before use."},"warnings":[{"fix":"Update to use Adapter() without arguments and pass model path to Enforcer.","message":"In version 1.5.0, the Adapter initialization changed. adapter = Adapter() now requires model_conf to be passed to the Enforcer, not to the Adapter.","severity":"breaking","affected_versions":"<1.5.0"},{"fix":"Run 'python manage.py migrate casbin_django_orm_adapter' after adding the app to INSTALLED_APPS.","message":"The adapter uses Django's ORM, so you must run migrations to create the casbin_rule table before using the adapter. Missing migration leads to table not found errors.","severity":"gotcha","affected_versions":"all"},{"fix":"Use adapter = Adapter() (no arguments).","message":"In version 1.6.0, the Adapter no longer accepts 'model' argument in its constructor; it must be initialized empty.","severity":"deprecated","affected_versions":"<=1.5.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Set os.environ['DJANGO_SETTINGS_MODULE'] = 'your_project.settings' and call django.setup() before importing Adapter.","cause":"Trying to import adapter before calling django.setup() or without DJANGO_SETTINGS_MODULE set.","error":"django.core.exceptions.ImproperlyConfigured: Requested setting ..., but settings are not configured."},{"fix":"Add 'casbin_django_orm_adapter' to INSTALLED_APPS in settings.py and run 'python manage.py migrate casbin_django_orm_adapter'.","cause":"Migrations for the casbin_django_orm_adapter app have not been applied.","error":"OperationalError: no such table: casbin_django_orm_adapter_casbinrule"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}