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

Solution:

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.

--

--

--

webdeveloper and programmer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Analyze BigQuery Query performance with Query Visualiser

Project Vs Product Thinking

Important docker commands to work.

A bit about me

Coming to grips with eBPF

Super easy C++ multi-threaded applications with Qt 6 and Concurrent

Dashflow —automate local development tasks

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

Ashwin.B

webdeveloper and programmer

More from Medium

Web Application Development Using Django-Python

Creating a simple tic-tac-toe game with Django / Channels / DRF / Celery and Typescript.

How To Deploy Your Django App On OVH (VPS with Nginx) + SSL certificate + Domain Name

Uploading chunk files in Django class based view using Cloudinary