Django Template Autor-reload

Viewed 298

How can i disable Django 3.2 from reloading the server whenever i edit template files in development. This is actually making my productivity slow because it takes 1-4 secs to reload.

3 Answers

Try with:

python manage.py runserver --noreload

Docs is here

This is a bug that currently has a ticket on Django's issue tracker, see Ticket #32744. This will be resolved in further versions, but until then from the discussion on the ticket itself we can see that the issue stems from the problem that newer Django projects use pathlib.Path while older projects just used strings for the paths. You can simply change your project settings to use pathlib.Path to solve this issue (at least for yourself). Make the following changes in settings.py (keep other settings unchanged):

from pathlib import Path


# Change the setting `BASE_DIR`
BASE_DIR = Path(__file__).resolve().parent.parent


# In the `DIRS` list of the setting `TEMPLATES`, for keeping it relevant I would only show that key
TEMPLATES = [
    {
        'DIRS': [BASE_DIR / 'templates'] # I don't show the other keys, but don't remove them!
    },
]


# the `DATABASES` setting if you use sqlite3
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}

The following is the way to work:

for x in TEMPLATES:
    if 'OPTIONS' not in x:
        x['OPTIONS'] = {}

    x['OPTIONS']['debug'] = True  # True: reload template on change
                                  # False: no reload on change
Related