tags:

views:

70

answers:

2

Hi folks,

just wondering if it would be possible in some experimental way, to edit django app code within django safely to then refresh the compiled files.

Would be great if someone has tried something similar already or has some ideas.

I would like to be able to edit small bits of code from a web interface, so I can easily maintain a couple of experimental projects.


Help would be great! Thanks.

+3  A: 

Providing an editing interface is one half of the battle but it's pretty straightforward. There are already apps out there to provide editing of templates and media files so it's pretty much just an extension of that.

The hardest part is restarting the server which would have to happen in order for the new code to be compiled. I don't think there's a way to do this from within the server so here's how I would do it:

  • When you make an edit, create a new file in the project root. eg an empty file called restart.
  • Write an bash script to look for that file, if it exists, restart the site and delete the file.
  • Cron the script to run once every 10 seconds. It shouldn't use any meaningful resources.

One serious issue is if you introduce bugs. You could test-compile (ie running the dev-server before you restart the site and check the input) but that's not very robust and you could easily end up in a situation where you lose access to the site.

As that's the case, it might be wise to set up the editor as a completely separate site so you're never locked out...

Oli
@Oli +1, I've been refreshing this page, waiting for an answer. Great answer! Maybe I can write a cron to refresh my page next time.
orokusaki
+2  A: 

SO question about wsgi servers that support automatic code reload. It should provide enough info to get you started.

Philip T.