javascript - Running server-side python in JS: difficulty with pico -
i have webpage needs run computation on start up. want keep computation on server side client cannot access source code. discovered pico, module supposed "a bridge between server-side python , client side javascript".
i have test.py:
import pico def hello(): return "hello world" my javascript simple:
pico.load("../../../test.py"); pico.main = function() { var displaymessage = function(message){ console.log("hello2"); console.log(message); } test.hello(displaymessage); } "../../../test.py" relative location of python script pico folder
i run "python -m pico.server" on command line. when go web page, open inspector, , go console error: "uncaught syntaxerror: unexpected token i". 'i' presumably first line import. note same error happens if don't run pico.server command.
any great, suggestions alternative methods of doing serverside vs clientside.
i may have answer you, have not been able replicate same error.
pico.loadnot seem work when file extensions included in argument, due function being designed load sub-modules directly (i.e. module.sub_module) in pico api:
pico.load(module, [callback])
load python module named module. module available global >variable of same name. submodules may loaded using dotted notation e.g. module.sub_module
to make sure included ".py" file extension on pico test page have been working on , failed load module, may problem if using file extension.
- another possible issue mentioned in comment holderweb. in first pico example html file client.js included in external
<script>tag, includes functionality required use pico. must have similar following tag in index.html head section:<script type="text/javascript" src="/pico/client.js"></script>
for more insight interested in seeing what/if server logs @ command line when error occurs, , contents of index.html page. hope helped!
Comments
Post a Comment