简体   繁体   中英

How can I call sympy by javascript with django / jquery or ajax

I'm sorry for this poor question, but I'm not realy familar with Python. Normally I'm working with PHP and JavaScript, but for my recent project I have to integrate some symbolic math to a webpage. In an Internet search, I came across Sympy. And sympy looks quite good. Up to now, I've installed sympy on my server and it works very well from the schell.

My problem looks like this:

  • The user should enter a formula in a inputfield.
  • The formula should be evaluated by sympy.
  • To do so, the value of the field should be posted to sympy. (Am I right, that this will work with django oder a simple jquery call? Can anybody give me an example, how to do so?)
  • Sympy has to evaluate the posted formula.
  • The return value should be posted back to JavaScript.

Can anyone please tell me how I can implement this.

Thanks a lot!

You can include the SymPy library into your views.py file and then create a new url that acts like an API. So when you pass the data to the API it runs through SymPy then prints out the value to the page. You can use jQuery to send a POST request to that page to get all the contents.

EDIT

import sympy

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