django-permissions-policy is a Django middleware that sets the Permissions-Policy HTTP header on your Django application. This header allows web developers to selectively enable or disable various browser features and APIs (e.g., camera, geolocation, autoplay) for the current document and any embedded iframes, enhancing security and privacy. The library, currently at version 4.29.0, is actively maintained with a regular release cadence.
pip install django-permissions-policyVerified import paths — ran on the pinned version, not inferred.
Add `PermissionsPolicyMiddleware` to your `MIDDLEWARE` setting, ideally after Django's `SecurityMiddleware`. Then, define your desired policy using the `PERMISSIONS_POLICY` dictionary in your `settings.py` file. You can also use `PERMISSIONS_POLICY_REPORT_ONLY` for testing policies without enforcing them.
Update middleware path in `settings.py` to `django_permissions_policy.PermissionsPolicyMiddleware` and setting names to `PERMISSIONS_POLICY` or `PERMISSIONS_POLICY_REPORT_ONLY`.
Ensure policy values for origins are raw strings without extraneous quotes, e.g., `['self', 'https://example.com']`.
Replace `"feature-name": "none"` with `"feature-name": []`.
Refer to the W3C spec or MDN for a full list of valid feature names and ensure correct origin syntax. Check Django logs for `ImproperlyConfigured` errors during startup.
Verify that `django_permissions_policy.PermissionsPolicyMiddleware` is positioned correctly in your `MIDDLEWARE` list.
Ensure that the keys in your PERMISSIONS_POLICY dictionary are valid browser feature names (e.g., 'camera', 'geolocation') and that values are lists of strings representing valid origins ('self', '*', or specific URLs like 'https://example.com').Install the package using pip: `python -m pip install django-permissions-policy`.
Correct the middleware path in `settings.py` to `django_permissions_policy.PermissionsPolicyMiddleware`.