How can I include a Python terminal / console in a Django application that users can execute python code against? For example, df.column_b * df.column_a
if the example data is:
column_a, column_b
1, 2
2, 4
3, 8
My use case is that it is easy for me to get data into my Django application. However, a common use case is for users to copy and paste the data into a spreadsheet and start doing some work / computation with the data. It would be nice if they didn't have to leave the page and could just do the computations directly in Python.
An example website is LearnPython.org. After inspecting the website a little bit, it looks like it uses CodeMirror.js. I have taken a look at the CodeMirror docs and the div
for LearnPython.org's Run
button, but it is not clear to me how I'd take the leap from registering an onClick
event to:
- Sending the code to the Django server
- Executing the code
- Sending the results back
Or could I do this all client side?
Any pointers in the right direction is greatly appreciated.