Search code examples
djangonginxdjango-viewsuwsgi

The change in the django view is not reflected to the page until restarting uwsgi


I installed Django + Uwsgi + Nginx. Project is running. But when i change something in the view, the change is not reflected to page until i restart uwsgi. Should i restart uwsgi everytime i make a change in the view? But when i add time to view to show in the page. The displayed time is changing everytime i refresh the page.

My view is :

from django.shortcuts import render
from django.http import HttpResponse   # added
from django.utils import timezone
def home(request):
    return HttpResponse('This is the home page. 101' + str(timezone.now()))

My urls.py :

from django.contrib import admin
from django.urls import path
from godentiapp import views    # added 

urlpatterns = [
    path('', views.home, name='home'),    # added
    path('admin/', admin.site.urls),  
]

Solution

  • Should [I] restart uwsgi everytime [I] make a change in the view?

    Yes, each time you change the source code, you need to restart the webserver, since the files are always loaded once. The Python interpreter will read the source file, and load it in memory. Changes the the file will not be reflected.

    If you work with Django in development mode, for modifications to the sourcde file it will automatically restart the server [Django-doc]:

    The development server automatically reloads Python code for each request, as needed. You don’t need to restart the server for code changes to take effect. However, some actions like adding files don’t trigger a restart, so you’ll have to restart the server in these cases.

    But this is thus not done in production, and should not be done, since this can result in security risks.