0

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.

Taras Zak
  • 31
  • 1
  • 5
  • 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 Dec 22 '15 at 12:58
  • 1
    You could use werkzeug which is able to do this kind of things. – jpic Dec 22 '15 at 15:11

1 Answers1

0

You need to take a look at eval and exec also it is potentially very dangerous from security point of view.

anand
  • 1,506
  • 14
  • 28