Skip to content
Advertisement

Serve Django views with React?

I am making a web application with react as frontend and django-rest-framework as backend.

For django, I am following a tutorial. https://www.techwithtim.net/tutorials/django/user-registration/ – here they have made a registration form with django that has proper validation.

Is there a way to do the same with React? Essentially, is there a way to show Django templates and views with React? If not, should I just link to the specific Django page hosted on the Django server?

Advertisement

Answer

First you have to create serializers for your login and registration view like this

JavaScript

and inside your views.py you have to create view like this

JavaScript

and you have to create endpoint for this to connect your frontend to you backend

urls.py

JavaScript

and than you have to call a method in you frontend application onSubmit or whatever you want

JavaScript

from Login method you will receive a response from that response you have to access alll the error in .catch() method like this

JavaScript

I think this is lot of code so I’ll stop here any more info I’ll provide you a tutorial URL.

UPDATE

UserSerializer

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement