Minimial test of database connectivity in django -
i'm writing quick little test view can get
every few minutes check application , database servers online , functioning.
from django.http import httpresponse, httpresponseservererror my_app.models import model def test(request): ''' returns httpresponse prove application/db servers work ''' if request.method == "get": #test database access count = model.objects.values_list('id', flat=true).count() if count: return httpresponse("ok") return httpresponseservererror("error")
is there more minimal inbuilt database query test db server working , takling app server, without having fake 1 did above?
you can import django connections , check databases:
from django.db import connections try: cursor = connections['default'].cursor() except operationalerror: return httpresponseservererror("error") else: return httpresponse("ok") return httpresponseservererror("error")
Comments
Post a Comment