0

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/wc-code@1.0.3/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

D.L
  • 1,738
  • 2
  • 12
  • 25

2 Answers2

0

I think you should learn flask or Django \

the solution here FLASK can be helpful

  • both `flask` and `django` are web frameworks. So inherently different as cannot run the cde directly from the browser (which is sometimes more convenient). They are launched from the command line. – D.L Mar 27 '22 at 14:08
0

Pyodide is a solution for embedding python inside a webpage.

Binoy Pilakkat
  • 121
  • 1
  • 5
  • The snipped of code in the question is from one of the links from Pyodid. That is where i got this code from. But can one import other modules from within the browser or is it just native python without modules ? – D.L Mar 27 '22 at 14:10
  • do you have an example of importing modules (assuming that this feature exists) ? – D.L Mar 27 '22 at 14:12
  • It seems pyodide doesn't ship all modules. Pl see https://pyodide.org/en/stable/usage/packages-in-pyodide.html for the list of standard packages. – Binoy Pilakkat Mar 29 '22 at 03:56
  • Pyodide documentation says that additional packages can be imported using micropip. Pl go through https://pyodide.org/en/stable/usage/api/micropip-api.html. – Binoy Pilakkat Mar 29 '22 at 03:58