A tool to inspect Django class-based views.
Project description
django-cbv-inspect
A Django app to help inspect all class-based views within your Django project 🔎 ✨
Inspired by django-debug-toolbar ❤️
📦 Installation
- Install with pip
pip install django-cbv-inspect
- Add
cbv_inspect
to your list ofINSTALLED_APPS
in your Django settings module
INSTALLED_APPS = [
...
"cbv_inspect",
...
]
- Add the middleware to your list of
MIDDLEWARE
classes in your Django settings module
MIDDLEWARE = [
...
"cbv_inspect.middleware.DjCbvInspectMiddleware",
...
]
-
Prerequisites
In your
TEMPLATES
settings within your Django settings module, make sure- the
BACKEND
setting is""django.template.backends.django.DjangoTemplates""
- the
APP_DIRS
setting isTrue
- the
🛞 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
from cbv_inspect.mixins import DjCbvExcludeMixin
class MyCoolView(DjCbvExcludeMixin, View):
pass
Exclude via decorator
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:
- View information
- CBV method call chain
- 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) 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 and 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! ✨
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-cbv-inspect-0.2.0.tar.gz
.
File metadata
- Download URL: django-cbv-inspect-0.2.0.tar.gz
- Upload date:
- Size: 15.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83a2911d55bcd15f89bb180c0dce7790a11edf40815adae107d7cd7049f983b9 |
|
MD5 | 1628d02e0736063fe274e332703d8173 |
|
BLAKE2b-256 | 5fd2d423081b59c9d0577f12419766419738dad6ba0a9b77af6eef56635f842e |
File details
Details for the file django_cbv_inspect-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: django_cbv_inspect-0.2.0-py3-none-any.whl
- Upload date:
- Size: 15.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14ed46e5eaa1ca143ae212c2ffd4c11e438c48f80b9626779f22464e90080543 |
|
MD5 | e035006434123c6a1f0c5602b5cd22bf |
|
BLAKE2b-256 | 8590f30cb75b4c0b1a65c8d7cf4ab76108c31b93c21c37642d1e74190c49ded1 |