Views¶
Health View¶
Health view of the confirm Django app.
- class confirm.django.views.health.HealthView(**kwargs)¶
Extensible health view.
Returns a JSON summary of the system health. Every
*_healthproperty is evaluated as a health check: if it returns without raising, the check ishealthy; if it raises, the check isunhealthy. A check may raiseSkipHealthCheckto be skipped (left out of the report). Add your own checks simply by defining further*_healthproperties on a subclass.A healthy response (status code
200) looks like:{ "status": "healthy", "message": "All checks are healthy.", "checks": { "database": "healthy" } }
As soon as one check fails the overall
statusbecomesunhealthy, the response has a500status code, themessageconcatenates the exception messages and anerrorsobject (keyed by check) carries them individually:{ "status": "unhealthy", "message": "Checks unhealthy: connection refused", "checks": { "database": "unhealthy" }, "errors": { "database": "connection refused" } }
Note
When the endpoint should stay reachable without authentication (e.g. behind
LoginRequiredMiddleware), expose it with thelogin_not_required()decorator.- property celery_health: None¶
Check Celery by verifying the broker connection and pinging the workers.
Skipped (via
SkipHealthCheck) when theCELERY_APPLICATIONsetting is not defined, i.e. when the project does not use Celery.
- property database_health: None¶
Check the default database by opening a cursor and running
SELECT 1.
- get(request: HttpRequest, *args, **kwargs) JsonResponse¶
Evaluate every
*_healthcheck and render the result as JSON.Returns a
200response when all checks are healthy, otherwise500. A check raisingSkipHealthCheckis left out of the report.
- exception confirm.django.views.health.SkipHealthCheck¶
Raised by a
*_healthcheck to signal that it does not apply and should be skipped — omitted from the report entirely, rather than counted ashealthyorunhealthy.
Generic Views¶
List Views¶
Generic list view.
- class confirm.django.views.list.ListView(**kwargs)¶
A
ListViewthat usesGenericTemplateNamesMixinfor generic template-name lookup, and names the object list in the context with the pluralised, snake-cased model name (seeget_context_object_name()).- get_context_object_name(object_list) str | None¶
Return the pluralised, snake-cased model name for the object list in the template context (or the explicit
context_object_nameif set).
Detail Views¶
Generic detail view.
- class confirm.django.views.detail.DetailView(**kwargs)¶
A
DetailViewthat combinesGenericTemplateNamesMixin(generic template-name lookup) withSnakeCaseObjectNameMixin(snake-cased context object name).
Create Views¶
Generic edit views.
- class confirm.django.views.create.CreateView(**kwargs)¶
A
CreateViewthat combinesGenericTemplateNamesMixin(generic template-name lookup) withSnakeCaseObjectNameMixin(snake-cased context object name).
View Mixins¶
Mixins for Django views.
- class confirm.django.views.mixins.GenericTemplateNamesMixin¶
Mixin for Django generic views that adds fallback template lookup paths.
On top of the usual
template_name, it also looks for app-specific and fully generic templates, so a set of sharedgeneric/*.htmltemplates can serve many models without a per-model template.The lookup can be tuned with these optional class attributes; each is auto-detected when not set:
template_name_app: the app name (detected from the view’s module)template_name_subdir: the sub-directory (the snake-cased model name)template_name_doc: the document name (fromtemplate_name_suffix)For a
Questionmodel in apollsapp, a detail view resolves to:polls/question/detail.htmlpolls/generic/detail.htmlgeneric/detail.html
See
get_template_names()for the exact resolution order.- get_template_names() list¶
Return the template lookup paths, ordered from the most specific (
template_name, then<app>/<subdir>/<doc>.html) to the fully genericgeneric/<doc>.html.See the class docstring for how
app,subdiranddocare resolved.
- class confirm.django.views.mixins.SnakeCaseObjectNameMixin¶
Mixin for Django single-object views that names the object in the template context after its snake-cased model name.
A
Questionobject thus becomes{{ question }}in the template, unless an explicitcontext_object_nameis set.- get_context_object_name(obj: Model) str | None¶
Return the snake-cased model name to use for the object in the template context (or the explicit
context_object_nameif set).