Reputation: 309
I'm creating an app with Django as the backend and React as the front-end. I already have the back-end built out, and now I'm trying to build out the React components.
My problem is this- right now I have my static files hosted on AWS. So every time I make a change to a component, I need to run collectstatic through django in order for my Django template to read the updated Main.js file.
Has anyone encountered this issue before? I am new to React, so I may be missing a very simple solution.
Thanks!!
Upvotes: 0
Views: 194
Reputation: 36
From what I can understand, it looks like your frontend (the React app and components) is too coupled with the backend (your django app). I would suggest you have your react app running as a standalone application, that you can develop locally and immediately react to changes you make (if you set-up your app with create-react-app
, this hot reloading will come out of the box). Then, if you wish to communicate with your backend, you should do so using http (typically in JSON), or, if you have media or other files, through a files storage system such as AWS S3. This way you don't need to collect your django app files everytime you change something on your frontend.
However, if you had to have your frontend coming out of your main.js
, you could still have a quicker reloading by having your django dev server serve your static files. If you already set the settings variable STATICFILES_STORAGE
, you could check if you're in development or production mode with the variable DEBUG
(which will typically be set to False in production), such as:
if not DEBUG:
STATICFILES_STORAGE = '<insert-your-staticfiles-backend-here>'
Upvotes: 0
Reputation: 487
Its a necessity.
Instead I would recommend only pushing to the AWS after you have tested and need the change(s) to be live.
Upvotes: 1