This Django Package Saved My Production Database — Meet django-read-only
Image Source: Unsplash

This Django Package Saved My Production Database — Meet django-read-only

2025-07-15 Rahul Beniwal
This Django Package Saved My Production Database — Meet django-read-only

Hey Django devs!
If you’ve ever feared accidentally writing to your production database – you’re not alone. Today, I’m sharing a game-changing Django package I recently discovered.

It’s like a seatbelt for your database: lightweight, powerful, and a true life-saver in production environments. Once you start using it, you’ll wonder how you ever lived without it.


🔗 Source Code on GitHub

Explore the implementation here:
👉 GitHub – Rahulbeniwal26119/intermediate-django


⚙️ Installation

To set up your Django project, follow this detailed guide:
📖 The Ultimate Guide to Django Setup Using Docker and Compose

Install the package using pip or uv:

pip install django-read-only

🛠️ Usage

Update your settings.py:

INSTALLED_APPS = [
    ...
    "django_read_only",
    ...
]

DJANGO_READ_ONLY = True 

Now your Django server will run in read-only mode. Let’s test it:

>>> first_user = User.objects.first()
>>> first_user.first_name = 'Rahul'
>>> first_user.save()

# DjangoReadOnlyError: Write queries are currently disabled. 
# Enable with django_read_only.enable_writes().

⚠️ But Wait — There’s a Catch!

Enabling read-only mode globally will lock your entire app – not ideal for production! Users won’t be able to perform any write actions on your website.

A better alternative: limit read-only mode to just the Django shell.


✅ Shell-Only Read-Only Mode

  1. Remove or set DJANGO_READ_ONLY = False in settings.py.
  2. Start the shell in read-only mode:
DJANGO_READ_ONLY=1 python manage.py shell

Now test it again:

>>> from django.contrib.auth.models import User
>>> user = User.objects.first()
>>> user.first_name = "Rahul"
>>> user.save()

# DjangoReadOnlyError: Write queries are currently disabled.

🧠 Dynamic Shell Control with IPython or ptpython

Already inside a shell but want to toggle read-only without restarting?

>>> from django.contrib.auth.models import User
>>> user = User.objects.first()
>>> user.save()  # This works for now

>>> %load_ext django_read_only
>>> %read_only on  # Turns on read-only mode
>>> user.save()

# DjangoReadOnlyError: Write queries are currently disabled.

💡 This is a super useful technique when debugging live issues on production.


✅ Conclusion

I found django-read-only incredibly helpful, especially when you need to debug production safely without risking accidental writes or deletes.

This little tool can prevent major headaches – definitely a must-have for serious Django developers.


🙌 Found it helpful?

Drop a 👏 and follow Rahul Beniwal for more deep-dive Django and Python content.


📚 More Django & Python Resources: