> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sevalla.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Django - Health checks

> Discover how to integrate health checks into your Django app in Sevalla.

To support zero-downtime deployments, configure a health check endpoint in your Django application. This endpoint allows Sevalla to verify that your app is running correctly before routing traffic to it.

There are multiple ways to implement a health check in Django, depending on the level of control and visibility required.

## Option 1: Use an existing view

If you don’t want to create a new endpoint, you can reuse an existing public view as the health check. The chosen path should return a successful response only when critical dependencies, such as the database or other required services, are functioning correctly. If a failure occurs, the view should return an error status.

## Option 2: Create a dedicated health check view

For more control and clarity, you can create a simple, dedicated health check endpoint. This view can explicitly verify core dependencies, such as database connectivity, by calling `connection.ensure_connection()`. If a connection cannot be established, an exception is raised, and the endpoint returns an error response, indicating the application is unhealthy.

```python theme={null}
# views.py
from django.db import connection
from django.http import HttpResponse

def health_check(request):
    connection.ensure_connection()
    return HttpResponse("OK", status=200)
```

```python theme={null}
# urls.py

urlpatterns = [
    path('health_check/', views.health_check, name='health_check'),
]
```

This view can then be extended with any other checks that your app needs to perform to assess its health.

## Option 3: Use a health check library

You can also use established libraries that provide ready-made health check endpoints. These libraries can automatically verify the health of multiple components, such as databases, caches, task queues, and email services. One example is [**Django Health Check**](https://github.com/revsys/django-health-check), which offers modular checks and configurable endpoints, making it a good choice for more complex applications with multiple dependencies.
