0

Is possible to refresh django server online?

I want that django refesh as is in (python manage.py runserver), however i want to make this using a django view.

How comand allow to refresh server online?

Thank you.

Caio Euzébio
  • 182
  • 1
  • 1
  • 10
  • This sounds like a really bad idea. But if you really need to, you can run unix commands from inside your python script using [`subprocess.run()`](https://docs.python.org/3/library/subprocess.html?highlight=subprocess#module-subprocess). More info and examples [here](https://stackoverflow.com/a/51950538/1252711) – dirkgroten Feb 10 '20 at 12:08
  • I realy need to rerun only 1 script insile a specific dir, however i 3 weeks searching about and don't get at the moiment, the only solution i found is refresh server. – Caio Euzébio Feb 10 '20 at 12:12
  • "re-run only 1 script inside a specific dir" what kind of script is that? When do you need to re-run it? Why does it run when you restart your server? Why not just call that script directly when you get a request to re-run it? This sounds like you're having an XY problem (asking the wrong question for a problem you're not explaining). – dirkgroten Feb 10 '20 at 12:16
  • its a router, its being executed only 1 time and not updating once i load a new file. – Caio Euzébio Feb 10 '20 at 12:40
  • I not asking the wrong question, i need to exec a .py sile inside a django, however i cant find a way to do this. – Caio Euzébio Feb 10 '20 at 12:44
  • what's a router? Is it a python script? And what do you mean "not updating once i load a new file", what new file? Please explain the details, show us the "router" and explain under which conditions it needs to run again. And yes, you are asking the wrong question, you're asking how to restart the django server whereas you should ask how do I run the script. – dirkgroten Feb 10 '20 at 12:45
  • This is my project, look in 'app/as_dash.py", this file as_dash.py execute only one time, i want that this code identify once 'media/' files change however it dont work because it runs only one time. https://github.com/CaioEuzebio/DjangoDashboard – Caio Euzébio Feb 10 '20 at 12:55
  • Why don't you wrap all that code in one or more functions that you call inside your views? for example instead of declaring `dforderbypn` globally, make a function `get_dforderbypn()` that returns it, so every time it's called, your `filename` gets recalculated (and all the data frames with it). – dirkgroten Feb 10 '20 at 13:02
  • i tried, however i have a dispathcer and dispatcher return a error once i store all inside a function. – Caio Euzébio Feb 10 '20 at 13:10
  • Then you should fix that error, there's no reason why it shouldn't work. There's no other way. – dirkgroten Feb 10 '20 at 13:16
  • Thath, was my fear Sir. Wellm let's code, i will make some refact and return here the results. – Caio Euzébio Feb 10 '20 at 13:19
  • Yes, i resolved storing all my pandas dataframes in the same router function before 'return' layout html. – Caio Euzébio Feb 10 '20 at 16:00

0 Answers0