https://github.com/sjbitcode/django-cbv-inspect
A tool to help inspect Django class-based views
https://github.com/sjbitcode/django-cbv-inspect
class-based-views debugging-tool django python python3
Last synced: 5 months ago
JSON representation
A tool to help inspect Django class-based views
- Host: GitHub
- URL: https://github.com/sjbitcode/django-cbv-inspect
- Owner: sjbitcode
- License: mit
- Created: 2021-10-30T17:10:48.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T13:43:35.000Z (over 3 years ago)
- Last Synced: 2025-09-26T03:41:05.849Z (9 months ago)
- Topics: class-based-views, debugging-tool, django, python, python3
- Language: Python
- Homepage:
- Size: 8.42 MB
- Stars: 59
- Watchers: 4
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
django-cbv-inspect
A tool to help inspect all class-based views within your Django project ๐ โจ
Inspired by django-debug-toolbar โค๏ธ
---
## ๐ฆ Installation
1. Install with pip
```
pip install django-cbv-inspect
```
2. Add `cbv_inspect` to your list of `INSTALLED_APPS` in your Django settings module
```python
INSTALLED_APPS = [
...
"cbv_inspect",
...
]
```
3. Add the middleware to your list of `MIDDLEWARE` classes in your Django settings module
```python
MIDDLEWARE = [
...
"cbv_inspect.middleware.DjCbvInspectMiddleware",
...
]
```
4. Make sure your `TEMPLATES` settings uses the `DjangoTemplates` backend with `APP_DIRS` set to `True`
```python
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"APP_DIRS": True,
...
}
]
```
---
## ๐ Usage
When all installation steps are done, any html response rendered by a class-based view should display the `django-cbv-inspect` toolbar on the page.
By default, all class-based views will be processed by the middleware. If you wish to exclude views, there are two options:
### Exclude via mixin
```python
from cbv_inspect.mixins import DjCbvExcludeMixin
class MyCoolView(DjCbvExcludeMixin, View):
pass
```
### Exclude via decorator
```python
from django.utils.decorators import method_decorator
from cbv_inspect.decorators import djcbv_exclude
@method_decorator(djcbv_exclude, name="dispatch")
class MyCoolView(View):
pass
```
---
## ๐งช Run locally
You can run the `example` project locally to test things out!
Clone the project and from the root of the repo, run the following Make command to setup the `example` project:
```
make run-example
```
To run unittests with coverage, run
```
make coverage
```
---
## โก๏ธ Features
The `django-cbv-inspect` toolbar has three main sections:
1. View information
2. CBV method call chain
3. MRO classes
### View information
This section shows high level information about the class-based view, request, and url.
### CBV method call chain
This is the main section that shows all methods that were excuted for the current class-based view:
It shows:
- method name and signature
- [Classy Class-Based Views (ccbv.co.uk)](https://ccbv.co.uk/) links
- method arguments and return value
- all resolved `super()` calls defined in the method
- module location
### MRO classes
This section lists all MRO classes of the current class-based view class.
This can come in handy especially with the prior section when mapping the execution of a class-based view.
---
## โ Why did I build this?
Django class-based views are hard to grasp especially when you're new to Django.
Fortunately for us, tools like [django-debug-toolbar](https://github.com/jazzband/django-debug-toolbar) and [ccbv.co.uk](https://ccbv.co.uk/) are super helpful in providing extra context for debugging.
My goal for this app was to take what goes on under the hood in a class-based view and display it in an easy to use interface, just like what django-debug-toolbar does.
Hopefully this can help debug your class-based views!
Happy coding! โจ