I have an endpoint
urls.py
from django.urls import path
from . import views
app_name = 'Main'
urlpatterns = [
path("helloKitty/", views.helloKitty, name='helloKitty'),
]
views.py
def helloKitty(request):
hello = pd.read_csv('static/data/helloKitty_data.csv')
hello = hello.to_json(orient='records')
return HttpResponse(hello)
It’s currently accessible by anyone at /helloKitty and it needs to be prevented.
I use React on the front-end to access this endpoint and retrieve the data
import React from "react";
import { create } from 'zustand';
import axios from 'axios';
const kittyStore = create((set) => ({
kitten: [],
fetchKitty: async () => {
const response = await axios.get('/helloKitty');
const hello = response.data.map((h) => {
return {
name: h.name,
age: h.age,
}
});
set({ kitten })
},
}));
export default kittyStore;
The endpoints /helloKitty
needs to be protected from being publicly accessible, and just the React app can view and fetch the data.