在重新启动UWSGI之前,Django视图中的更改不会反映到页面
我安装了django
+ uwsgi
+ nginx
。 项目正在运行。但是,当我更改view
中的内容时,在我重新启动uwsgi
之前,更改不会反映到页面。我是否应该在每次更改view
中重新启动uwsgi
? 但是,当我将时间添加到view
以在页面中显示。每次我刷新页面时,显示的时间都在更改。
我的视图
是:
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()))
我的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),
]
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),
]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是,每次更改源代码时,您都需要重新启动Web服务器,因为该文件始终加载一次。 Python解释器将读取源文件,并将其加载到内存中。更改文件将不会反映。
如果您使用开发模式中的Django ,对于Sourcde文件进行修改,它将自动 restart 服务器  [django-doc] :
但这不是在生产中进行的,不应进行,因为这可能会导致安全风险。
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]:
But this is thus not done in production, and should not be done, since this can result in security risks.