Registry / web-framework / django-braces

django-braces

JSON →
library1.17.0pypypiunverified

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-braces
INSTALL
IMPORT
SIG · DJANGO-BRACES
D
django-braces
web-frameworkpythonv1.17.0
Install
3.4s avg
Import
Disk
66MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.17.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 66.4MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 3.4s · import 0.000s · 67MB
66MB installed
● package 66MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

LoginRequiredMixin
from braces.views import LoginRequiredMixin
from braces.views import LoginRequiredMixin

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`.

from django.views.generic import TemplateView from braces.views import LoginRequiredMixin class SomeSecretView(LoginRequiredMixin, TemplateView): template_name = "path/to/secret_template.html" login_url = "/login/" # Optional: Redirect URL if not authenticated redirect_field_name = "next" # Optional: Parameter name for the next URL raise_exception = False # Optional: Raise PermissionDenied instead of redirecting def get(self, request, *args, **kwargs): return self.render_to_response({})
Debug
Known issues
breakingExplicit support for Python versions before 3.7 and non-LTS versions of Django was dropped in `django-braces` v1.15.0.
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.
affects: >=1.15.0
deprecatedThe `CreateAndRedirectToEditView` mixin was marked for deprecation since v1.0.0 and subsequently removed in v1.11.0.
fix
If upgrading from older versions, replace `CreateAndRedirectToEditView` with custom `get_success_url` logic or a combination of other mixins.
affects: >=1.11.0
gotchaPrior to v1.9.0, certain access mixins (like `MultipleGroupRequiredMixin` and `GroupRequiredMixin`) could lead to redirect loops for users without appropriate permissions or group memberships.
fix
Upgrade to `django-braces` v1.9.0 or newer to benefit from fixes addressing these redirect loop issues.
affects: <1.9.0
gotchaThe `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.
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.
affects: <1.0.0
gotchaThe `PermissionRequiredMixin` will raise an `ImproperlyConfigured` exception if the `permission_required` attribute is not explicitly set on the view class.
fix
Always set the `permission_required` class attribute as a string (e.g., `'app_label.add_model'`) when using `PermissionRequiredMixin`.
affects: All
gotchaThe `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`.
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.
affects: All
Upgrade
Version history
1.17.0latest on PyPI · released Mar 18, 2025
Audit
Dependencies
DjangorequiredCore framework dependency for all functionality.
Agent activity
26 hits · last 30 days
node
24
OpenAI (training)
1
Resources
django-braces — pip install django-braces · libregistry