Making REST-API using djando + react js #165282
Replies: 1 comment
-
|
First, set up Django with the Django REST Framework (pip install django djangorestframework) and create a model with fields like title and description. Add a serializer and a viewset using ModelViewSet, then register it with a router in your URLs so your API works at something like /api/posts/. Don’t forget to enable CORS (django-cors-headers) so React can connect. On the frontend, use create-react-app and install axios. In your form component, capture the title and description, then send them to your Django API with axios.post("http://127.0.0.1:8000/api/posts/"). When you submit, Django will save the data, and you’ll see it instantly appear in your API. That’s all you need for a simple React + Django connection — it’s a great first project to learn how the frontend and backend talk to each other! 🚀 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am a newbie in my programming career, and I want to learn how to create a REST API and connect React.js with Django. I'm trying to build a simple blog API. I've already created a form in React with fields for the title and description, just for practice. Since this is my first attempt, I want to keep things simple. If anyone can help me, I would really appreciate it! ;)
Beta Was this translation helpful? Give feedback.
All reactions