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.

2
  • You want to run the python code on your server after sending from the browser? Or you want to do everything in the browser? Commented Dec 22, 2015 at 12:58
  • 1
    You could use werkzeug which is able to do this kind of things. Commented Dec 22, 2015 at 15:11

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.