title: How to set timeout for database connection in django
body: <p>I have mysql database as engine for django. Django works thought nginx via fastcgi with timeout in 1 min (after that nginx says "504 gateway time-out").</p>
  
  <p>If database gone down, django is trying reconnect to DB and waiting for response from it. And waiting for response too long (more than 1 minute) that nginx returns to client the 504 error code. </p>
  
  <p>How to set timeout for db connecton in django? And what the right way to handle this event and return to client a pretty page with "Sorry database is out of service now. Please try later" instead of technical 504 error page? </p>