-2

plot.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://fonts.googleapis.com/css2?family=Open+Sans&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.14.0/css/all.css" integrity="sha384-HzLeBuhoNPvSl5KYnjx0BT+WB0QEEqLprO+NBkkk5gbc67FTaL7XIGa2w1L0Xbgc" crossorigin="anonymous">
    <link rel="stylesheet" type="text/css" href="../static/css/css5.css">
    <title>Protein Structure Analyzer</title>
    <script type="text/javascript" src="../static/jquery/jquery-3.6.3.js"></script>
    <script src="../static/brython/Brython-3.11.1/brython.js"></script>
    <script src="../static/brython/Brython-3.11.1/brython_stdlib.js"></script>
</head>
<body onload="brython()">
<div class="angry-grid">
    <div class="header-div">SURPASS Plots</div>
    <div class="plot-div"></div>
    <div class="form-div">
        <form></form>
    </div>
    <div class="footer-div">
        Footer
    </div>
</div>
<script type="text/python">
from PersistanceUtils import *

energy_list, time_list = PersistanceUtils.get_plot_data2("{{unique_key}}")

</script>
</body>
</html>

Debug

brython.js:9479          GET http://127.0.0.1:5000/PersistanceUtils.py?v=1676882840703 404 (NOT FOUND)
brython.js:9484 Error 404 means that Python module PersistanceUtils was not found at url http://127.0.0.1:5000/PersistanceUtils.py
brython.js:9479          GET http://127.0.0.1:5000/PersistanceUtils/__init__.py?v=1676882840718 404 (NOT FOUND)
brython.js:9484 Error 404 means that Python module PersistanceUtils was not found at url http://127.0.0.1:5000/PersistanceUtils/__init__.py
brython.js:9479          GET http://127.0.0.1:5000/static/brython/Brython-3.11.1/Lib/site-packages/PersistanceUtils.py?v=1676882840737 404 (NOT FOUND)
brython.js:9484 Error 404 means that Python module PersistanceUtils was not found at url http://127.0.0.1:5000/static/brython/Brython-3.11.1/Lib/site-packages/PersistanceUtils.py
brython.js:9479          GET http://127.0.0.1:5000/static/brython/Brython-3.11.1/Lib/site-packages/PersistanceUtils/__init__.py?v=1676882840753 404 (NOT FOUND)
brython.js:9484 Error 404 means that Python module PersistanceUtils was not found at url http://127.0.0.1:5000/static/brython/Brython-3.11.1/Lib/site-packages/PersistanceUtils/__init__.py
brython.js:14320 Traceback (most recent call last):
  File "http://127.0.0.1:5000/plot#__main__", line 1, in <module>
    from PersistanceUtils import *
ModuleNotFoundError: PersistanceUtils

There is a file named PersistanceUtils.py in the application root. The Brython script is unable to load it.

How can I load it?

enter image description here

davidism
  • 121,510
  • 29
  • 395
  • 339
user366312
  • 16,949
  • 65
  • 235
  • 452

1 Answers1

0

You can place your python files for Brython inside the static folder. Then you import them with a script tag, whereby an id attribute has to be specified.

<script type="text/python" id="demo" src="{{ url_for('static', filename='demo.py') }}"></script>

In the import commando you now refer to the defined id of the module.

<script type="text/python">
    from demo import *
    
    # Use your import here.
</script>

Detlef
  • 6,137
  • 2
  • 6
  • 24