-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Web2Py support: ImportError('No module named react.render',) #70
Comments
Hi, There's no obvious reason why Web2Py would be the problem. My guess would be Can you provide more detail, e.g.:
For context, my suspicion here is that either your python setup is broken (and the interpreter can't find the libraries), or you may need to run a different command to start the process. |
What OS and version are you on? What python version (python --version)? What command are you using to start the python process? If you start a python interpreter with just python, then run import react. What happens? If it works, can you try react.file?
It seems that when I run the app it doesn't get access to the react file. Could it be solved by copying or symlinking to this file inside the I am first trying it out on a local instance, but once I get it working it will be deployed on a CentOS server. |
Adding I haven't looked at the zip you linked, but my guess is that the web2py app is using its own python interpreter, not your system or venv binary. If you check the web2py docs, they might have instructions for how to install libraries within their system. |
Thanks for the reply, based on your input I found the Third party modules chapter in the documentation:
In order for the error to disappear I had to copy more than just the |
No worries, best of luck with it. I think there's a way for pip to install locally, something like |
The local install into the modules folder worked. However I have this If I try to do the Web2Py way of the basic example: ...
rendered = render_component(
os.path.join(os.getcwd(), 'static', 'js', 'CommentBox.jsx'),
{
'comments': comments,
'url': '/comment/',
},
to_static_markup=True,
)
... ...
rendered = render_component(
# '../static/CommentBox.jsx',
# OR
URL('static','CommentBox.jsx'),
{
'comments': comments,
'url': '/comment/',
},
to_static_markup=True,
)
... I get the above error. So it seems that in Web2Py my urls are not pointing to the file correctly. I tried relative and absolute both in different and same folder. In the end I got it working by using: rendered = render_component(os.path.dirname(os.path.abspath(__file__)) + '/CommentBox.jsx', {'comments': comments, 'url': '/comment/'}) Any ideas on where I can look to find the issue? Also using this way around for now I managed to setup the render server. But eventhough I use the basic example templates I get the following error:
|
The path provided to the renderer needs to be an absolute path to the file, so your last example should work fine. I usually have something like ROOT = os.path.dirname(__file__)
# ...
rendered = render_component(
os.path.join(ROOT, 'path', 'to', 'CommentBox.jsx'),
{'comments': comments, 'url': '/comment/'}
) |
I see, for it to work properly I need to place the templates in a sub folder. I was thinking to use it as:
Any idea what is wrong with the jsx file? Is it my babel not configured correctly or is something up with the file? As far as I can tell the syntax is correct? |
Hard to tell with the encoding artifacts, but I'd guess that it hasn't installed the jsx plugin. You'll need to make sure that the |
Thanks. I finally managed it to show up. It was indeed the fact that
I updated this answer with the final setup so other people using web2py would have a better insight in how to get react working. So what I had to do to get it to work with Web2Py:
from react.render import render_component
from gluon import *
import os
def test_render(comments, url):
rendered = render_component(os.path.dirname(os.path.abspath(__file__)) + '/node_render_server/templates/CommentBox.jsx', {'comments': comments,'url': url})
return XML(rendered)
from my_react import test_render
def index():
react_test = test_render([],'https://github.com')
return dict(message=T('Welcome to web2py!'),my_react_test=react_test)
...
<div id="react-test">{{=my_react_test}}</div>
...
<script>
var comments = [];
var url = 'http://www.github.com/some/other/url';
ReactDOM.render(
React.createElement(/*App.components.CommentBox or url?*/, {'comments': comments,'url': url}),
document.getElementById('react-test')
);
</script> NOTE: I am not sure about the absolute path to the component, but I use webpack and make sure of
Overview of folder setup:
|
Links to @Anima-t3d's investigation in #70
Thanks for the write-up, @Anima-t3d. I've added a FAQ section to the docs and linked to your above comment. |
Does this work with Web2Py? I am relatively new to python and Web2Py. I want to implement react server side rendering in an existing Web2Py application.
I tried the following on a local instance:
pip install react
and createdmodules/react_test.py
:It will give an error
ImportError('No module named react.render',)
.Did I do something wrong or is it because I am trying to use
python-react
with Web2Py?Thanks in advance.
The text was updated successfully, but these errors were encountered: