Like the title says, I'm running a django webapp using Brython (NOT Javascript), hosted on Heroku, and would like to import a .py file located in the static folder. I am able to import and display the contents of the .py file, but when I try to import it, the webpage remains blank (white screen) with no errors (status 200). My debugging is possibly not developed enough to catch the error, but usually I will get a traceback when I have errors as debugging is on. So, the status 200 and blank white screen are important, I believe. Although debugging is not the subject of my post, any short insights into why I'm getting this result would be of interest.
Here's the code I'm trying in the html template with a couple failing examples, and one suboptimal solution that does run mostly as hoped:
<body onload="brython()">
<script type="text/python">
from browser import document, html
# This line works and displays the contents of the .py file in browser,
# used to rule out my staticfile options in settings
document <= html.H1( open("{% static 'my_py_script.py' %}").read(), Id="main")
# Here is one method I've tried that causes the browser to remain blank on load
# even though status is 200. I hope it will demonstrate what I'm aiming for.
import "{% static 'my_py_script.py' %}"
# I've seen this line suggested on stackOverflow as a non-brython solution
# It also causes the page to be blank, status 200. I'm including it here so
# people know I've checked the threads, but also curious if it is just
# incompatible with Brython, or if there is something I'm doing wrong here?
from django.templatetags.static import static
# This next line executes with the desired result, but I've read that exec() is
# quite slow and I'd prefer to use Python's import command if possible.
# If this is not accurate, please let me know!
exec(open("{% static 'my_py_script.py' %}").read())
</script>
</body>
Thanks in advance for any help!