Open yrik opened 9 years ago
Wow, that's a really "strange" idea to run a server application framework on the clint :P
What is your real intention to do this?
Even more "stange" then pypy.js? :) @jedie To show test app in a browser. Like https://jsfiddle.net but for Django.
It would be nice to have a "distributed computing" between local area browsers... Just to let the "strange" bigger.
Hi @yric, sounds like an interesting challenge, let's see if we can figure it out :-)
First, you'll need to make sure you've bundled all of your python packages together where pypy.js can find them, as described in [1]. Then you can probably run manage.py
with arguments by doing something like this:
pypyjs.exec("import sys; sys.argv = ['manage.py', 'runserver']").then(function() {
return pypyjs.execfile("/path/to/manage.py")
})
Although you'd have to figure out what the path to your bundled manage.py
will be at runtime. I'll be pretty surprised if this works first try, but it could be interesting to see how far it can get!
Wandering, can pypy.js make external connections to DB like MYSQL?
Not directly, since webbrowsers can't really create raw TCP sockets from javascript. You might be able to set up a server-side proxy using something like websockify [2] to let the JS in your browser talk to MySQL, but I haven't looked into it in any detail.
Let me know if you plan to play around with any of this, and I'll do what I can to advise.
[1] https://github.com/pypyjs/pypyjs/blob/master/README.dist.rst#importing-python-modules [2] https://github.com/kanaka/websockify
Instead of usind MySQL, just use SQlite. But sqlite3 module isn't available, see: https://github.com/pypyjs/pypyjs/pull/52
But starting 'manage.py runserver' will not really work: It starts the develop server on 127.0.0.1:8000
@rfk
Thank you for suggestions.
I made a fork, added Django to packages and made test fiddle. https://jsfiddle.net/kz77vf3r/7/
Ended with issue that Django is depended on subprocess
module, which is not supported.
Is there any way to mock some packages from EXCLUDE_MODULES, so it can emulate real work?
>>> import django
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/lib/pypyjs/lib_pypy/django/__init__.py", line 1, in <module>
from django.utils.version import get_version
File "/lib/pypyjs/lib_pypy/django/utils/version.py", line 5, in <module>
import subprocess
ImportError: No module named subprocess
See https://github.com/pypyjs/pypyjs/pull/167 for some work-in-progress on getting more of the stdlib running, either by mocking it out or by re-implementing the bits we can.
Hello. Thank you for gorgeous work.
I'm trying to run a Django using pypy.js but can't figure out first steps. Usually I run
python manage.py runserver
to start the app being in folder with project files. Here I see onlypypyjs.execfile("/path/to/some/file.py");
where I don't know ho to pass a parameters. Also I see that sqllite3 module is not supported.. Wandering, can pypy.js make external connections to DB like MYSQL?Would be thankful for any help towards running Django on pypy.js.