Django code changes not reflected without restart

In my project the DEBUG option is True but after updating and reloading the template the change is not reflected.

**My os is windows 10.

But after reading server update is reflected.

But I want to see the change after reloading the page without restarting the server.

  • Before updating

from django.shortcuts import render

from django.http import HttpResponse

# Create your views here.

def index(request):

`context = {`

'name': `'before updating`',

`'age': 25,`

`'nationality': 'United Status'`

`}`

return render(request, 'index.html', context)

-after updating

from django.shortcuts import render

from django.http import HttpResponse

# Create your views here.

def index(request):

context = {

'name': 'after updating',

'age': 25,

'nationality': 'United Status'

}

return render(request, 'index.html', context)

-here is my template code

<h1>

Welcome, {{name}}

</h1>

Someone help me.

Restarting the server process is the only way for Django to reflect changes in code (not templates). The code is loaded into the Python interpreter and remains resident there.
If you’re using runserver (or runserver_plus), it will detect that code changes have been made and will restart the server process. Otherwise, you need to do it yourself.

Side note: When posting code here, don’t enclose each line between single backticks - `. Enclose the entire block of code between lines of three backticks. This means you’ll have a line of ```, then all the lines of code, then another line of ```. (And you can do this multiple times in your post to separate different blocks of code.)

runserver by default uses a stat based approach to reload on code changes. There are a few instances were it fails to reload, but generally (as long as all files are valid) it should do so.

1 Like