How could django monitor file change and refresh development server?

162 views
Skip to first unread message

est

unread,
Mar 21, 2008, 6:53:11 PM3/21/08
to Django users
I am just curious how could django's buildin development server could
monitor the .py source file is updated and automatically refresh
server. How did django do that?

What module did django use?

I wish I could add some fun stuff with this. e.g. Save your source
code & django will automatically refresh the browser!

Collin Grady

unread,
Mar 21, 2008, 8:23:50 PM3/21/08
to Django users
> I wish I could add some fun stuff with this. e.g. Save your source
> code & django will automatically refresh the browser!

That would not really be plausible :)

scott lewis

unread,
Mar 21, 2008, 9:10:28 PM3/21/08
to django...@googlegroups.com

That depends. If you're running Safari on a Mac it's somewhat trivial.

The autoreload functionality is in django.util.autoreload. Adding
something along the lines of:

os.system("""osascript -e 'tell application "Safari" to do JavaScript
"document.location = document.location;" in document 1'""")

to restart_with_reloader() to send a reload event to Safari would
achieve the goal. The only real problem would be tweaking the timing
somehow so that Safari actually gives Django enough time to finish
reloading.

Of course, that's not much use on Windows or Linux.

scott.

est

unread,
Mar 22, 2008, 7:48:16 AM3/22/08
to Django users
Thanks! I'll look into that.

When i saied auto-refresh browser, I really meant IE. I really like
scripting IE...........Though many of you may think this sucks........
Reply all
Reply to author
Forward
0 new messages