Django Braces provides a collection of reusable, generic mixins designed to simplify the use of Django's class-based views. These mixins often replicate the functionality of Django's function-based view decorators, addressing common development challenges with class-based views. The library is considered stable and mature, focusing its support on Python versions still receiving fixes and Django LTS releases. The current version is 1.17.0.
pip install django-bracesVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to use the `LoginRequiredMixin` to restrict access to a Django class-based view. The mixin ensures that only authenticated users can access `SomeSecretView`, redirecting unauthenticated users to the specified `login_url`.
Ensure your project runs on Python 3.7+ and a supported Django LTS version before upgrading to django-braces v1.15.0 or later.
If upgrading from older versions, replace `CreateAndRedirectToEditView` with custom `get_success_url` logic or a combination of other mixins.
Upgrade to `django-braces` v1.9.0 or newer to benefit from fixes addressing these redirect loop issues.
For versions 1.0.0 and later, configure `LoginRequiredMixin` using `login_url`, `redirect_field_name`, and `raise_exception` class attributes directly on your view.
Always set the `permission_required` class attribute as a string (e.g., `'app_label.add_model'`) when using `PermissionRequiredMixin`.
If your user model or group setup is custom, override the `check_membership` method within your view using `GroupRequiredMixin` to implement your specific group checking logic.