Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to reload the view without restarting Django?

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.

like image 692
storm Avatar asked Feb 07 '12 20:02

storm


3 Answers

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

like image 66
jdi Avatar answered Nov 14 '22 23:11

jdi


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.

like image 30
Shatz Avatar answered Nov 14 '22 23:11

Shatz


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).

like image 28
markmnl Avatar answered Nov 14 '22 22:11

markmnl