splitting brython app into multiple files

126 views
Skip to first unread message

Łukasz Grabowski

unread,
Aug 8, 2017, 2:49:42 PM8/8/17
to bry...@googlegroups.com
Hi I have trouble splitting brython files for my flask app.

What I orignally had was basically all brython in a single template
file which is served by flask, basically like this:

myapp/
templates/
index.html
static/
brython.js
myapp.py


So all brython code used to be in index.html. Now I'm trying to include
brython code from a file static/brython_stuff.py. This works, but I
can't get it work if in brython_stuff.py I include

import more_brython_stuff

seemingly no matter where I put more_brython_stuff.py. Any suggestions
what should I try?

Thanks
Lukasz

Łukasz Grabowski

unread,
Aug 8, 2017, 10:03:43 PM8/8/17
to bry...@googlegroups.com
> Hi I have trouble splitting brython files for my flask app.

To follow up on that, I have two further questions:

1) is there a way to have multiple brython scripts, for example
something along the lines of
<script type ='text/python' src= 'a.py' id=a></script>
<script type ='text/python' src= 'b.py' id=b></script>

and then import one into the other, for example to have in b.py
import a
?


2) Is there a way to tell brython to look for a *.py file instead of
other possibilities? Currently I set explicitly pythonpath as an
argument for brython, but it takes painfuly long time, because first I
get:

Error 404 means that Python module domwriter was not found at
url /user0/static/domwriter.js brython.js:6940:1
Error 404 means that Python module domwriter was not found at
url /user0/static/domwriter.pyc.js brython.js:6940:1
Error 404 means that Python module domwriter was not found at
url /user0/static/domwriter/__init__.pyc.js

and only then brython actually loads what it should i.e. domwriter.py


Best,
Lukasz

Kiko

unread,
Aug 9, 2017, 3:58:55 AM8/9/17
to bry...@googlegroups.com
If it is ready for production why not use a precompiled bundle of all the code.


OTOH, Jinja templates are server side managed. If you want to use, e.g., an element created by brython in a Jinja template the element would not exist when the info is passed to the template from flask, it would exist only when is served and brython could start to work. I fon't know if this makes sense.


Best,
Lukasz

--
You received this message because you are subscribed to the Google Groups "brython" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brython+unsubscribe@googlegroups.com.
To post to this group, send email to bry...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/brython/20170809030335.2ffe7940%40brutus.lancaster.ac.uk.
For more options, visit https://groups.google.com/d/optout.

tjnau...@gmail.com

unread,
Aug 9, 2017, 6:27:04 AM8/9/17
to brython
Hi Lukasz,

Further to kiko's comment, an explanation for how to bundle files with the current released version of Brython can be found here:
http://www.brython.info/static_doc/en/import.html

Tom.

Best,
To unsubscribe from this group and stop receiving emails from it, send an email to brython+u...@googlegroups.com.

To post to this group, send email to bry...@googlegroups.com.

tjnau...@gmail.com

unread,
Aug 9, 2017, 7:35:04 AM8/9/17
to brython
Hi Lukasz,

I think the problem here is that morebrythonstuff.py at not at the webserver root where Brython expects it by default.

You could try the following:
1. Make sure your directory myapp/ is in your webserver's root (www/), or symlinked there.
2. Add an empty __init__.py file to myapp/ to make it a package.
3. In brythonstuff.py import it as "import myapp.morebrythonstuff"

This assumes that your file morebrythonstuff.py is in myapp/ .
If your webserver will transparently serve "/myapp/static/brython_stuff.py" as "/myapp/brython_stuff.py" then the way you have it in a subdirectory static/ will be fine.

Best regards,
Tom.
Reply all
Reply to author
Forward
0 new messages