Home > database >  run python script from within html in the browser
run python script from within html in the browser

Time:03-28

This is a python inside html question.

I have been looking for some time and have come across this code that embeds python inside a webpage (html).

I have tested it and it works. Here is the code:

The code script is saved as *.html and opens (and runs) in the browser.

<!DOCTYPE html>
<head>
<script type="module" src="https://cdn.jsdelivr.net/gh/vanillawc/[email protected]/src/wc-code.js"></script>
</head>
<body>
  <wc-code mode="python">
    <script type="wc-content">
       a = 1
       b = 1
       print(a b)
    </script>
  </wc-code>                                                                                         
</body>

The <script> tag in the code above contains some basic python code.

However, i cannot seem to import modules with a standard import module call and was wondering if there was a way of doing this ?

Also, similarly, if there is a way of calling or importing a custom python script like my_code.py ?

Thanks

CodePudding user response:

I think you should learn flask or Django \

the solution here FLASK can be helpful

CodePudding user response:

Pyodide is a solution for embedding python inside a webpage.

  • Related