Fastest way to temporarily take your django site down (maintenance).

If you have a major update to make to your django site, including some large data migrations that will take some time. Your site has enough traffic that this will certainly impact at least a few users. you would like to temporarily put up an “under construction” static page while you complete the update. What’s would be the best approach to do this on pythonanywhere?

Note: This solution works even on your local server

What you’ll need to do is comment out the code in your wsgi.py file, and then add code like this underneath — it’s raw WSGI code that will just respond to every request with a “site down for maintenance” response:

def application(environ, start_response):
status = '200 OK'
content = "Site down for maintenance"
response_headers = [('Content-Type', 'text/html'), ('Content-Length', str(len(content)))]
start_response(status, response_headers)
yield content.encode('utf8')

Once you’re done that, reload the site from the “Web” page and check it to make sure that it’s working the way you want (If you are on local server just refresh the page and everything will be working perfectly fine.). You can modify what it displays by changing the content string -- just put any HTML you like in there.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ashwin B

I love the internet, technology and building beautiful things