{"id":6590,"library":"django-braces","title":"Django Braces","description":"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.","status":"active","version":"1.17.0","language":"en","source_language":"en","source_url":"https://github.com/brack3t/django-braces/","tags":["django","mixins","class-based-views","cbv","authentication","permissions"],"install":[{"cmd":"pip install django-braces","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Core framework dependency for all functionality.","package":"Django","optional":false}],"imports":[{"symbol":"LoginRequiredMixin","correct":"from braces.views import LoginRequiredMixin"},{"symbol":"PermissionRequiredMixin","correct":"from braces.views import PermissionRequiredMixin"},{"note":"PermissionRequiredMixin only handles a single permission; use MultiplePermissionsRequiredMixin for multiple permissions.","wrong":"from braces.views import PermissionRequiredMixin (for multiple permissions)","symbol":"MultiplePermissionsRequiredMixin","correct":"from braces.views import MultiplePermissionsRequiredMixin"},{"symbol":"GroupRequiredMixin","correct":"from braces.views import GroupRequiredMixin"},{"symbol":"CsrfExemptMixin","correct":"from braces.views import CsrfExemptMixin"},{"symbol":"JSONResponseMixin","correct":"from braces.views import JSONResponseMixin"}],"quickstart":{"code":"from django.views.generic import TemplateView\nfrom braces.views import LoginRequiredMixin\n\nclass SomeSecretView(LoginRequiredMixin, TemplateView):\n    template_name = \"path/to/secret_template.html\"\n    login_url = \"/login/\"  # Optional: Redirect URL if not authenticated\n    redirect_field_name = \"next\" # Optional: Parameter name for the next URL\n    raise_exception = False # Optional: Raise PermissionDenied instead of redirecting\n\n    def get(self, request, *args, **kwargs):\n        return self.render_to_response({})\n","lang":"python","description":"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`."},"warnings":[{"fix":"Ensure your project runs on Python 3.7+ and a supported Django LTS version before upgrading to django-braces v1.15.0 or later.","message":"Explicit support for Python versions before 3.7 and non-LTS versions of Django was dropped in `django-braces` v1.15.0.","severity":"breaking","affected_versions":">=1.15.0"},{"fix":"If upgrading from older versions, replace `CreateAndRedirectToEditView` with custom `get_success_url` logic or a combination of other mixins.","message":"The `CreateAndRedirectToEditView` mixin was marked for deprecation since v1.0.0 and subsequently removed in v1.11.0.","severity":"deprecated","affected_versions":">=1.11.0"},{"fix":"Upgrade to `django-braces` v1.9.0 or newer to benefit from fixes addressing these redirect loop issues.","message":"Prior to v1.9.0, certain access mixins (like `MultipleGroupRequiredMixin` and `GroupRequiredMixin`) could lead to redirect loops for users without appropriate permissions or group memberships.","severity":"gotcha","affected_versions":"<1.9.0"},{"fix":"For versions 1.0.0 and later, configure `LoginRequiredMixin` using `login_url`, `redirect_field_name`, and `raise_exception` class attributes directly on your view.","message":"The `LoginRequiredMixin` was rewritten in v1.0 to align with other access mixins. Older implementations might not correctly utilize `login_url`, `redirect_field_name`, or `raise_exception` class attributes.","severity":"gotcha","affected_versions":"<1.0.0"},{"fix":"Always set the `permission_required` class attribute as a string (e.g., `'app_label.add_model'`) when using `PermissionRequiredMixin`.","message":"The `PermissionRequiredMixin` will raise an `ImproperlyConfigured` exception if the `permission_required` attribute is not explicitly set on the view class.","severity":"gotcha","affected_versions":"All"},{"fix":"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.","message":"The `GroupRequiredMixin` assumes that you are using Django's default `Group` model and that your user model has a `groups` ManyToMany relationship. Deviations require overriding `check_membership`.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}