I want to execute python code in my browser. Now I enter code in text-field in template, took it to view, where doing following:
source = request.POST.get('source', '').replace('"', r'\"')
result = commands.getoutput('python -c "%s"' % source)
I used python's module command for this, but I think it's don't correct way. Correct way is using code module, but I don't understand how to get result of execution code and organise REPL. Can you give a little tip how to do it, please?
UPD: I want to start interactive shell in my browser with some variables. User can write some functions to manipulate this vars in browser and see that comes out of it. I understand the danger of this, but now it is not relevant.
-
You want to run the python code on your server after sending from the browser? Or you want to do everything in the browser?Aravinda– Aravinda2015年12月22日 12:58:24 +00:00Commented Dec 22, 2015 at 12:58
-
1You could use werkzeug which is able to do this kind of things.jpic– jpic2015年12月22日 15:11:30 +00:00Commented Dec 22, 2015 at 15:11