Skip to content
Advertisement

Django dev server no longer reloads on save

I’m developing a simple Django app and things were going great until suddenly the dev server stopped reloading automatically on file change. Now I have to manually restart the server every time I change some Python file, which is pretty annoying.

I’ve tried removing my virtual environment and reinstalling Django to no avail so I guess the problem is with the project itself. In settings.py I have DEBUG = True and also when I start the server it says Watching for file changes with StatReloader, which I assume means that it should reload. Can’t think of what else it could be. I don’t think I even touched any settings files, just views, urls and models.

Advertisement

Answer

check your TEMPLATES of ‘settings.py`.

If you have defined your DIRS something like this:

'DIRS': [BASE_DIR , 'templates'],
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR , 'templates'],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

So change it to 'DIRS': [BASE_DIR / 'templates'], if you don’t do this it will cause the server to restart again and again.

like this:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR / 'templates'],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

It may solve your problem.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement