6

My question is how to structure the directories when you are creating an app that uses both Flask(backend) and Reactjs (frontend). The default structures for each individual infrastructures are below:

In Flask, the structure is:

.
├── app.py
├── static
│   ├── foo.png
│   └── bar.csv
├── templates
│   ├── Predict.html
│   ├── home.html
│   ├── index.html
│   └── something.js
└── utlities.py

In React apps, the structure (when running create-react-app) is:

.
├── node_modules
├── package-lock.json
├── package.json
├── public
│   ├── favicon.ico
│   ├── index.html
│   ├── logo192.png
│   ├── logo512.png
│   ├── manifest.json
│   └── robots.txt
└── src
    ├── App.css
    ├── App.js
    ├── App.test.js
    ├── index.css
    ├── index.js
    ├── logo.svg
    ├── serviceWorker.js
    └── setupTests.js

2 Answers 2

3

the way it has become standard is to keep the front end and backend separate, if using react they should not have html files in the flask project folders (it would only work for data handling)

Sign up to request clarification or add additional context in comments.

2 Comments

When you run the flask app doesn't it automatically look for the html files in the templates directory? How do you get it to look for the js files in the src directory instead? Thanks
its better your backend server dont serve the frontend files, you can use the serve package to run the frontend using npm run build and serve -s build
-1

Assuming we want to build a hello template I would first use the standard Flask folder organization :

.
├── hello_template
    ├── configurations.py
    ├── __init__.py
    ├── README.md
    ├── run.py
    └── templates
        ├── hello
        │   ├── __init__.py
        │   └── views.py
        ├── __init__.py
        ├── public
        │   ├── css
        │   ├── fonts
        │   ├── images
        │   └── js
        └── static
            ├── index.html
            ├── __init__.py
            ├── js
               ├── components
               ├── index.jsx
               └── routes.js

And then add React, by opening terminal in hello_template/templates/static/ and run the command :

$ npm i react react-dom --save-dev

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.