2

I have one big Django project consisting out of several small apps, independent from each other but partly sharing the same database or/and models.

All the apps are created with python manage.py startapp myappa so they have their own urls.py and views.py.

I started using create-react-app for the front end for two of those apps and connected them successfully by turning the index.html of the react project into a template and serve it through the views.py (more here).

Now each one of these create-react-app projects has its own build folder which's path I include in the STATICFILES_DIRS in settings.py to collect the static files.

It looks like this:

static/
templates/
myappa/
    build/
          static/
          index.html
          ... 
myappb/
    build/
          static/
          index.html
          ... 

Now, I was wondering if there is a way to have only one build folder that contains all built files respectively to their projects something like:

myappa/
myappb/
static/
templates/
build/
     myappa/
             static/
             index.html
             ... 
     myappb/
             static/
             index.html
             ...  

I'm imagining that this folder would live on the same level as the the static folder and the appa and appb folders.

One way, since by default I can't have the build folder outside the project folder structure(?) and I don't want to eject the project, I manually move all the build folders a couple of levels up so that it is on the same level as the app folders after the build process. That way I only have to include one path into to STATICFILES_DIRS. But I'm wondering if there is an automatic way of doing this.

I've been looking at other projects of django and React but unfortunately, most are rather small so they don't cover this case.

I was wondering if anyone had the same thoughts or maybe some nice big projects on github I can have a look at? Or am I wrong and by default having its own create react app in the separated apps makes sense?

Tom
  • 2,545
  • 5
  • 31
  • 71

0 Answers0