On Friday 24 April 2009 04:51:54 am realfun wrote:
> Hi,
>
> I build a website(fayaa.com) on Bluehost using Django, but this month
> database down 3 times, during that period, user can only see an
> "Unexpected Exception" message, is there a way to redirect to a 404
> page instead?
>
> Regards,
> -realfun

I've seen a settings option that is used as a check in other projects for such 
a situation. You can put the check in a custom middleware.

In settings.py add something like this:

# set to True to turn on maintaince page
MAINTAINANCE = True

and rewrite process_request to return the approriate response for a maintaince 
page based on the setting on a true setting or return None on a false 
setting, stating the site is going through maintainence or what ever message 
you want to tell them.

http://docs.djangoproject.com/en/dev/topics/http/middleware/#process-request

If you want to have the middleware check the availability of the db, I'm not 
exactly positive what you can check here in django.db, but possibly to check 
the connection, a thumb through django.db with ipython against a sqlite3 db, 
didn't show me a lot, but I also didn't go indepth into what each method is, 
for those I'm not 100% on.  But this check, I'm not positive how big of a 
performance hit it would be or not, since this would be checked on each 
request.  I've normally just set the maintaince flag manually when required.



Mike 



-- 
Big book, big bore.
                -- Callimachus

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to