Is it possible to reload the view without restarting Django?

假装没事ソ 提交于 2019-12-23 10:48:10

问题


After changing the view function without runserver again, and press F5 to refresh the page, Django will not reload the new view but use the previous one. but if you change the template, Django always uses the new one.

So, Is there a way to make Django reload the view every time the user refresh the page, I think that is very convenient for develop to modify the view function frequently.


回答1:


If you are running django using the dev server (./manage.py runserver) then it will always reload when it detects any code changes. This is even more efficient than reloading with every request. If you make a change, it reloads when it needs to.

If you are running a production server (nginx, apache, etc) and you want code-reload, then you need to add something to your wsgi module to detect code changes.

Code reloading with apache: http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode

Code reloading with uwsgi: http://projects.unbit.it/uwsgi/wiki/TipsAndTricks




回答2:


It is a known issue with PyDev. I would suggest running the server from terminal/cmd. cd to your project directory where manage.py is present and run the server using

python manage.py runserver

You don't need to run the project from eclipse menu. Any changes made in eclipse would be reflected as soon as they are made.




回答3:


If you are running Django as a WSGI application in daemon mode you just need to touch the wsgi.py for your site and it will reload the application next time there is a request. (So no need for any special options).




回答4:


I noticed it is a setting in pyDev run configurations. I wonder why but it seems --noreload is configured by default. So I edit arguments of run settings and now the server is reloading also when editing views.




回答5:


Try using gunicorn or nginx as running server... They dont restart on code change try typing

gunicorn --bind 0.0.0.0:8080 app.wsgi:application



来源:https://stackoverflow.com/questions/9183114/is-it-possible-to-reload-the-view-without-restarting-django

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!