web123456

Eel - How to call python functions in js

It has a local web server that then lets you comment functions with Python so that they can be called from Javascript and vice versa.
Inevitably, if you want to obtain data from the backend language, you must open a server, and Eel can avoid writing servers.

pip install eel   # Install eel

Expose python functions to js

@               # Expose this function to js
def your_python_function(a, b):
    return a+b

For the decorator, the python function decorated by the decorator can be called freely in js

Introduce eel in js and call python functions

  <script type="text/javascript" src="/"></script>
  <script type="text/javascript">
       eel.your_python_function(1,2);  // Call Python functions
  </script>

Start python program and enable micro server for web pages

('web') #Give a folder containing web files
 ('') # Start entering the loop and automatically start your home page

‘web’——> Your web page path contains all the css and js files used on the home page, otherwise an error will be reported.
‘’——————>Your homepage file name
/*_/article/details/80754634
In this article, there is a simple application example. Everyone is welcome to discuss the use of Eel with me.