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

Question:

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?

Asked By: user18965527

||

Answers:

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.

Answered By: Sunderam Dubey
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.