Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Trouble with Static Files and Components in Django Deployment #166

Answered by Archmonger
dnl0037 asked this question in Problem
Discussion options

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?

You must be logged in to vote

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

Comment options

Are you using ReactPy-Django? If so, you can use the Django CSS component.

You must be logged in to vote
1 reply
Comment options

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?

Comment options

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

You must be logged in to vote
2 replies
Comment options

Did you make sure to run python manage.py collectstatic?

Comment options

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.

Comment options

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 %}
You must be logged in to vote
30 replies
Comment options

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.

Comment options

If that doesn't catch all your issues, I might need to see your repo if possible.

Comment options

I would really appreciate if you take a look: https://github.com/dnl0037/djangorp. The component.py is inside the main directory.

Comment options

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.

Answer selected by Archmonger
Comment options

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!

Comment options

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.

Comment options

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.

Comment options

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /