简体   繁体   中英

Include python console in Django application to interact with dataset

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.

Have you seen this project ?

What is DataCamp Light, and how can I use it?

In addition to an extensive course library, DataCamp also offers 'Open Courses' that any DataCamp user can create and take. If you already have MOOC (Massive Open Online course) content you would like to publish using the DataCamp learning environment, you can get started here: https://www.datacamp.com/teach and see some examples here: https://www.datacamp.com/community/open-courses .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM