-
-
Notifications
You must be signed in to change notification settings - Fork 22
Trouble with Static Files and Components in Django Deployment #166
-
Hello! After a bit of research and work, I hooked up my ReactPy components to Django, and I'm running deployment tests. However, I've run into the inconvenience that the static files (such as the CSS style) have a peculiar way of being handled, which I am not doing yet, and thus they don't load. But the ReactPy components won't load either. Should I treat them as static files?
Beta Was this translation helpful? Give feedback.
All reactions
Seems to work for me with DEBUG off. If you're having issues with remote hosting, you might need to look into WebSocket configuration with your hosting provider.
Replies: 3 comments 33 replies
-
Are you using ReactPy-Django? If so, you can use the Django CSS component.
Beta Was this translation helpful? Give feedback.
All reactions
-
If this is not your issue, I'm going to need more details about what specific problems you're having.
For example you said sometimes your components don't load, are you getting any errors in console?
Beta Was this translation helpful? Give feedback.
All reactions
-
Hi. Yes, I am using ReactPy-Django. In my computer, everything loads fine, but now I uploaded my project to "pythonanywhere.com". Here, the login (which is not a component) loads but the main page (which is a component) does not. It throws me this error that I think is causing the problem:
Not Found: /static/reactpy_django/client.js
Beta Was this translation helpful? Give feedback.
All reactions
-
Did you make sure to run python manage.py collectstatic?
Beta Was this translation helpful? Give feedback.
All reactions
-
Additionally, when running in production (settings.py:DEBUG = False) Django has no built-in way of serving static files.
Most Django developers end up using Whitenoise to fill this gap.
Another common configuration involves serving static files using Nginx.
Beta Was this translation helpful? Give feedback.
All reactions
-
Yep, I run the "collectstatic" command and started using the "whitenoise" library. I placed the components in the static file alongside the stylesheets. Now the CSS works, including the CSS for the components (I can see the background color), but the components themselves don't load. I'm getting these kinds of errors:
2023年08月04日 22:52:06,437: Not Found: /reactpy/static.components.adminpage/1fc84cc50c1d422e9482a96a9c3be94f/
My code for loading the component is:
{% block content %}
{% component "staticfiles.components.adminpage" user %}
{% endblock %}
Beta Was this translation helpful? Give feedback.
All reactions
-
Can you install the latest version (3.3.0) of reactpy-django? I've added a ton of automated checks and they might catch some of your configuration issues.
These checks only run if settings.py:DEBUG = True.
Beta Was this translation helpful? Give feedback.
All reactions
-
If that doesn't catch all your issues, I might need to see your repo if possible.
Beta Was this translation helpful? Give feedback.
All reactions
-
I would really appreciate if you take a look: https://github.com/dnl0037/djangorp. The component.py is inside the main directory.
Beta Was this translation helpful? Give feedback.
All reactions
-
Seems to work for me with DEBUG off. If you're having issues with remote hosting, you might need to look into WebSocket configuration with your hosting provider.
Beta Was this translation helpful? Give feedback.
All reactions
-
Thank you very much for checking it out. I just searched for the WebSockets configuration of the "PythonAnywhere" server provider, and they said that they do not support them... I learned the hard way, haha. I will now look for another provider. Thank you again for your help!
Beta Was this translation helpful? Give feedback.
All reactions
-
Hey, I wanted to let you know that when I installed the lastest version of reactpy-django, the app started to be a bit laggy. With all the changes I was making I did't know why it was happening. But a few minutes ago I returned to the previous version and it began to run smoothly again.
Beta Was this translation helpful? Give feedback.
All reactions
-
If the issue is first-render time, ReactPy now uses the database to keep track of when it needs to perform cleaning. Therefore, a slow database speed will result in slow first render times. You can try a higher performance database to fix this.
If the issue is re-render time (such as click events), you can try turning off settings.py:REACTPY_BACKHAUL_THREAD.
Beta Was this translation helpful? Give feedback.
All reactions
-
I see. I've been using the database that django provided, sqlite3 (and only for saving the users, which are maybe 2 or 3.) If I set "REACTPY_DATABASE = "default", does Reactpy connect itself to it?
Beta Was this translation helpful? Give feedback.