Skip to main content
https://github.com/adamchainz/django-read-only/workflows/CI/badge.svg?branch=master https://img.shields.io/pypi/v/django-read-only.svg https://img.shields.io/badge/code%20style-black-000000.svg

Disable Django database writes.

Requirements

Python 3.5 to 3.8 supported.

Django 2.2 to 3.0 supported.


Deploying a Django project? Testing a Django project? Are your tests slow? Check out my book Speed Up Your Django Tests which covers loads of best practices so you can write faster, more accurate tests.


Installation

Install with pip:

python -m pip install django-read-only

Then add to your installed apps:

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

Usage

Set the environment variable DJANGO_READ_ONLY to anything but the empty string, and all data modification queries will cause an exception:

DJANGO_READ_ONLY=1 python manage.py shell
...
>>> User.objects.create_user(username="hacker", password="hunter2")
...
DjangoReadOnlyError(...)

You can put this in the shell profile file (bashrc, zshrc, etc.) of the user on your production system. This way developers performing exploratory queries can’t accidentally make changes, but writes remain enabled for non-shell processes like your WSGI server.

During a session with DJANGO_READ_ONLY set, you can re-enable writes for the current thread by calling enable_writes():

>>> import django_read_only
>>> django_read_only.enable_writes()

Writes can be disabled with disable_writes():

>>> django_read_only.disable_writes()

To temporarily allow writes, use the temp_writes() context manager / decorator:

>>> with django_read_only.temp_writes():
...      User.objects.create_user(...)

Metadata

Release files for django-read-only 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-read-only 1.0.0
File Size Uploaded
django-read-only-1.0.0.tar.gz 7.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-read-only 1.0.0
File Interpreter ABI Platform
django_read_only-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.7 kB

Release files / django-read-only-1.0.0.tar.gz

Download URL django-read-only-1.0.0.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
28b4196f97b212af6a1d534bc156bbe2140d56d9972526d5c9c5899bab826b1f
BLAKE2b-256 checksum
How to use checksums
f0b90129bde13eff7d4934614dd4ed89c45fcf57256efc807b7d17d59f6d5f43
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

Release files / django_read_only-1.0.0-py3-none-any.whl

Download URL django_read_only-1.0.0-py3-none-any.whl
Size 4.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
465c7d59e3c3f28207a2bc7a5861b7ac4536543ae3a09f0c9e3aba87bc4e0a59
BLAKE2b-256 checksum
How to use checksums
5249a7e45cf7c0f66c7254a3570c6dfbd311e798477fb2450adc8509958b002c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

Release history Release notifications | RSS feed

1.21.0

2 release files

1.18.0

2 release files

1.17.0

2 release files

1.16.0

2 release files

1.15.0

2 release files

1.14.0

2 release files

1.13.0

2 release files

1.12.0

2 release files

1.10.0

2 release files

1.9.0

2 release files

1.8.0

2 release files

1.7.0

2 release files

1.6.0

2 release files

1.5.0

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page