Skip to content

auscode/ReactDjango

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

React-Vite & Django Integration Techniques

This repository contains code and instructions for integrating a React front-end with a Django back-end using two powerful techniques. The integration methods discussed in the repo aims to provide flexibility and productivity for developers working with these technologies.

Table of Contents

  1. Introduction
  2. Same Infrastructure Integration
  3. Separate Infrastructures Integration
  4. Setting up React with Vite in Django
  5. Connecting Static Files
  6. Production-Level Integration
  7. Building and Debugging
  8. Hot Module Replacement and Django Integration
  9. Alternative Method: Separate Codebases
  10. Enabling CORS for Secure Asset Fetching
  11. Linking Django REST Framework with React-Vite

Introduction

In this section, the video introduces the two main integration techniques: using the same infrastructure and passing data through JSON or having separate infrastructures for independent deployments and enhanced productivity.

Same Infrastructure Integration

This section covers the details of integrating React with Django in the same infrastructure, discussing the challenges and benefits of this approach.

Separate Infrastructures Integration

Explore the advantages of having separate infrastructures for React and Django, including independent deployments and automatic failover.

Setting up React with Vite in Django

Learn how to set up a front-end React application within a Django back-end project using Vite. The process includes creating a front-end folder, setting up a new React project, and integrating it into the Django project.

Connecting Static Files

Understand how to connect static files from the front-end React application to the back-end Django server. The section covers importing the OS module, connecting static files directories, and writing code under roll-up options.

Production-Level Integration

This section explains the steps to integrate React-Vite and Django for a production-level application. Topics include adding static files to Django settings, disabling debug mode, and configuring the HTML for production.

Building and Debugging

Explore the process of building and debugging a React application using Vite and Django. Understand the importance of debugging, controlling debug mode, and resolving common issues.

Hot Module Replacement and Django Integration

Learn how to use Vite's hot module replacement feature to manage new static files created by Django. The section emphasizes the importance of handling small errors and ensuring correct file names.

Alternative Method: Separate Codebases

Discover an alternative method of having two separate codebases for React and Django. This includes using Create React App with Websockets for real-time data communication and setting up the environment for successful deployment.

Enabling CORS for Secure Asset Fetching

Understand the importance of CORS setup for secure asset fetching. The section covers the installation of plugins, enabling CORS headers, and adding CORS allowed origins in the middleware.

Linking Django REST Framework with React-Vite

Explore the integration of Django REST Framework with React-Vite, including setting up session authentication and adding CORS middleware and headers.

Conclusion

The speaker concludes the video by summarizing the integration techniques and addressing the complexities of integrating a React front-end with a Django back-end.

Feel free to explore each section for detailed instructions and code snippets. Happy coding!

References:

Documentation

Vite Backend Integration

YT Video

Youtube video for reference

About

Using Frontend as Vite React and Backend as Django (Complete Connection)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published