How to do back-end in ReactJS- (Is it possible) - reactjs

I am new to web development I want to create an application using React and Django but all tutorials show that by using REST API.
is there a way to use Django and react without REST API and perform CURD.

I recommend also reading this blog post https://www.valentinog.com/blog/drf/, where Django and React are integrated via mini React apps inside Django templates.
I am not sure if it is the best approach, but may be useful.

React JS is a frontend JavaScript library. Whatever data is received by React from the backend, it's supposed be in JSON format and Django, if used without REST FRAMEWORK, doesn't pass JSON objects. It passes Query sets instead which are not acceptable and iterable in React. So, you have to use Django REST Framework, which makes use of serialisation and deserialisation for CRUD operations and hence creating REST APIs.

No, it's not possible.
Because even ReactJS is supposed to be on client side(Frontend). npm run build generates HTML/CSS/JS bundle for your app.
For backend, you might need node-express/Django rest... etc
HERE is complete guide to integrate your app.

Yes, you can do that with Django but in the end you need a API, no matter if it is REST or GraphQL because Django take care about the backend and React do all the stuff in the front end and you will need a way to connect both (and you do that by using an API)
I recommend you to use Django Rest Framework if you want to use a REST API or Graphene if you want to use a GraphQL API, here is a very cool tutorial to start with graphql.

Related

Do I need Inertia to use Laravel + React

I want to move app and I am looking to new technologies. I have no experience with Laravel, but I wonder if I want to create a Laravel + React web app do I also need to look at Inertia, or I can do Laravel + React without Inertia?
NO. You can build an app with Laravel and React as your front-end without Inertia.
HOWEVER, if you're looking into building an SPA, I'd recommend looking into Inertia, since it makes the process of integrating the back-end and front-end a lot easier and you won't need to write an API to get them talking to each other.
Backing up a bit #Matheus 's answer.
The purpose of Inertia is to be able to create an SPA application using the laravel routing system.
You can create your routes in your web.php, that would point to a Controller's function and that function would return a React component with your data as props.
This takes away a lot of work on both sides. Without inertia you would need a frontend application made in this case with React, then useEffect would be responsible for calling an api in your laravel application to then retrieve just the data so you can use it on your frontend application.
Either way is possible, although if you are a fullstack taking care of both, the frontend and backend I recommend Inertia to save yourself some time and CSRF token pain :)

is it possible to add separate frontend like react for existing flask python project

Joined in an existing project with flask python, it is a combined backend with template to show html on front end, is there a way I add a separate from end framework like react for new features? like the existing ones are kept untouched, just add new features with react in front end?
or have to implement new features in the flask?
basically the concern is with flask python, websites not that modern. I know we can also use bootstrap or semantic UI,but not sure. quite new in react. for the flask, get to know from last week...any help will be really appreciated.
The best way is to convert the existing flask app to a REST API the classic way that flask uses is that the server returns a template (HTML page) using information in the DB. Another way is instead of returning a template, the server should returns JSON data that the client (React, VueJS, Angular, Android, IOS...) can get it (with tools like Axios...) and display it to the user.
Flask-RESTful is an extension for Flask that adds support for quickly building REST APIs.

Is there any method of integrating ReactJS and Django without implementing Django Restful API?

Guys as you may know when using Vanilla JS you can just deliver html files to Django and just code between the lines in Python language in order to create the functionalities that you need in your backend side of your web application. However this is not the case when we use React JS. Is there any similar way(as vanilla JS and html files)for integrating REACT.JS and Django(except for using rest api endpoints)?
Maybe using react and Django are two different technologies and you need APIs to interact whereas this is not the case writing vanilla js in Django HTML files.
It's called React Server-Side Rendering. If you add Django to this and search for it, you'll get a couple of hits, like this tutorial bellow:
https://medium.com/meural-product-development/setting-up-server-side-rendering-with-react-redux-and-django-4d6f4d2fd705
Looks doable as long as you are somewhat proficient in Node as well.

Need to Deploy Laravel + Reactjs (SEO friendly ) application

I have to create an application where users will have their unique usernames and profiles like "website.com/JohnDoe". for that the client asked me to develop it in any good PHP framework and client also need an android/ios app (which he disclosed after 2nd meeting) . so I was(before 2nd meeting) going to use Laravel totally. but since he said he wanted a mobile app too, so I decided to use Laravel as backend API, for Web frontend I will use Reactjs and for Mobile I would use ReactNative ( I've done same before). since Laravel provides react support so my I was planning to use React within the laravel.
Then client said he is more concern about SEO of his website. so I had two options
Use laravel as API provider only. and create ReactJS app totally separate from Laravel.
In this case I will need Nodejs server. Then I thought If I have a nodejs server than why would I go for laravel, I could use Express.
Use ReactJS within laravel and use any SSR package to cope with ssr.
If I am going for second option, can anyone point me to already live website which uses React Helmet SSR or Laravel-react-ssr?
Laravel react-ssr: https://github.com/spatie/laravel-server-side-rendering
React Helmet-ssr: https://github.com/nfl/react-helmet#server-usage
I have read both, and I am too confused. I am beginner in both Laravel and React(node) so I am unable to understand what both are proposing.
i deployed your 2 option mentioned let me give you the site https://v3.topviewnyc.com/, i created a microservice which would take care of SSR besides my hooks and components are build on react so am totally able of enjoy the SPA frontend side with react using components and get data via laravels API

What is the best architecture to integrate AngularJS with Django?

I am trying to integrate Angular with Django. I have 2 approaches which one is the best way:
Build a separate angular app and serve it's static files to django to render. In this way the routing and rendering everything will be handled by Angular.
Or to build templates in django using Angular directly and use MVT architecture of Django only.
Which is the correct way from architecture point of view? If not these two please suggest any good approach.
I'm not using AngularJS (actually I'm using VueJS but it's kinda the same) but here is what is usually done :
You do your models as usual, using Django. It defines your database structure.
You build an API that exposes your datas. For that you can use DRF (Django Rest Framework) for a REST API or graphene-django to build a GraphQL API)
You code components to build pages. And you retrieve your datas to display from the API.
For my project, I personnally use :
Django
graphene-django for a GraphQL API
Apollo Client to fetch data from the GraphQL API
VueJS for the frontend components
There are lots of tutorials on how to combine all of these so I guess there are some for AngularJS too.
You should be able to do something similar with AngularJS.
Finally, it is more like the first approach that you described. You'll have some build step that will create a bundle of files with a index.html or similar. The thing to do is to tell Django : "Hey, for any URL, point to that file".
Note that the thing I'm describing is for building a SPA (Single Page Application).

Resources