Search code examples
pythonbrython

Using same rendering code for client side and server side


Does Brython has a recommended method for using the same rendering code in the server side?

To do this currently I'm using my own browser module emulating Brython's on the server side for html rendering (https://github.com/yairchu/vote_tool/blob/master/browser.py), but I wonder if there's a better way..


Solution

  • The portion of code you are using is short, elegant, and quite specific - it will be Python compatible on the server side, as you have noted, and you it won't be easy to find another piece of code for this kind of rendering that is so concise and able to work on Brython's client side (as it does not yet achieve 100% compatibility with Python).

    That said, I think it is more than ok to reuse this code on the server side on your project.

    Note that by carefully laying out files in your project directories, it is possible to have some files to be imported both on server and client side. If done correctly, this can make a great deal of work simpler.