Launch React or Vue in template
Use case
Let's say you are building a Django project, for some reason, you need to add a complex dashboard page to the project. React
or Vue
seems good option here, however, you do not want to move the whole project to SPA
, now this pattern can help you.
You can use React
or Vue
to render the specific pages or specific components in your python web project.
Workflow
Notes:
- When user visit the website, Python web server process the request, render HTML.
- The browser download JS, run it to init React or Vue app
Frontend
- We can create django-react project from django-react-boilerplate
- Or we can add React/Vue to the Webpack boilerplate (python-webpack-boilerplate), and then load the frontend app in Django template using the custom template tag.
Pros and Cons
Pros:
- We can develop in
hybrid
mode, for example, we can useReact
orVue.js
to build some complex components, and write other parts still using Django template or Jinja. - Can still use some features such as form, built-auth.
Cons
- The component rendered by React or Vue is not SEO friendly (same problem as
SPA
)