'Why do i have to restart the Django server every time I make some changes in views?

I am new to Django and every time I make a change in veiws.py or urls.py I have to run python manange.py run server. This is hectic as for every small change I have to restart the server. Is there any fix? Or is this normal?



Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1