Q.
6 MVT from local author + django program(in 5th question)
Q. 5,7,8,9(same answer)
Step 1: Set Up Django Backend
1. Create and activate a virtual environment
2. Install Django, Django REST Framework, and CORS headers
3. Create a Django project and one app
4. Add the app, REST framework, and CORS settings in settings.py
5. Create a model (like Item)
6. Run migrations to apply the model
7. (Optional) Create a superuser to access the admin panel
🔹 Step 2: Set Up API
1. Create a serializer for the model
2. Create a viewset using Django REST Framework
3. Register the viewset with a router in urls.py
4. Add the app's URLs to the main urls.py
5. Run the Django server
6. Open the API in a browser or Postman to test
🔹 Step 3: Set Up React Frontend
1. Create a new React app using Create React App
2. Install Axios to make API calls
3. Create a component to get and show data
4. Use useEffect and useState to call the API and store data
5. Show the data in a list or table
🔹 Step 4: Connect React to Django
1. Allow CORS in Django settings so React can access the API
2. Use the correct Django API link in React
3. Start both servers:
o Django server runs on port 8000
o React app runs on port 3000
4. Open the React app in browser and see data from Django
EXAMPLE PROGRAM
1.Django Backend (Core Files)
models.py
from django.db import models
class Item(models.Model): name = models.CharField(max_length=100)
2.React Frontend (App.js)
import React, { useEffect, useState } from 'react';
import axios from 'axios';
function App() {
const [data, setData] = useState([]);
useEffect(() => { axios.get('http://localhost:8000/api/items/').then(res =>
setData(res.data)); }, []);
return <ul>{data.map(i => <li key={i.id}>{i.name}</li>)}</ul>;
export default App;
3. Node.js Backend (Express API)
Install dependencies:
npm init -y
npm install express cors
Create server.js:
const express = require('express');
const cors = require('cors');
const app = express();
app.use(cors());
app.get('/api/data', (req, res) => res.json([{ id: 1, name: 'Item 1' }]));
app.listen(5000, () => console.log('Backend running on
http://localhost:5000'));