views:

139

answers:

1

I am using Django and Postgresql as my DBMS.

I wish to set a setting that enables to enable/disable database connection. When the connection is set to closed (in settings.py) the site will display a message such as "meintanence mode" or something like that. Django will not show any db connection error message (or mail them to admins). It is appreciated if django do not try to connect to the database at all.

+2  A: 

Maybe creating a middleware solves your problem. Put your new middleware "maintenancemiddleware" as the FIRST item of your settings.middleware tuple.

# code not tested, only for demonstration.
# maintenancemiddleware.py
from django.conf.settings import MAINTENANCE

class MaintenanceMiddleware(object):
    def process_request(self, request):
        if MAINTENANCE:
           # redirect to a static url (like /media/maintenancemode.html)

Further info: http://docs.djangoproject.com/en/1.2/topics/http/middleware/#topics-http-middleware

mawimawi