I am sending request from react to django to know if we've this user or not. django is sending response back but it's not even showing in console in react.
here is my React Code:
const BASE_URL = 'http://127.0.0.1:8000/writer-login/'
function TeacherLogin() {
const[writerLoginData, setWriterLoginData] = useState({
'writer_email' : '',
'writer_password': ''
});
const handleChange = (event) => {
setWriterLoginData({
...writerLoginData,
[event.target.name]:event.target.value
})
}
const submitForm = () => {
const writerLoginFormData = new FormData();
writerLoginFormData.append('writer_email',writerLoginData.writer_email)
writerLoginFormData.append('writer_password',writerLoginData.writer_password)
try {
axios.post(BASE_URL,writerLoginFormData).then((res) => {
console.log('Found')
console.log(res.data)
if(res.data === true) {
localStorage.setItem('writerLoginStatus',true)
window.Location.href="/writer-dashboard";
}
})
} catch (error) {
console.log(error)
}
}
const writerLoginStatus = localStorage.getItem('writerLoginStatus')
if(writerLoginStatus === 'true'){
window.Location.href="/writer-dashboard";
}
return (
<div className='App'>
<Form.Label>Email address</Form.Label>
<Form.Control value={writerLoginData.writer_name} onChange={handleChange} name ="writer_email" type="email" placeholder="Enter email" />
<Form.Text className="text-muted">
We'll never share your email with anyone else.
</Form.Text>
</Form.Group>
<Form.Label>Password</Form.Label>
<Form.Control value={writerLoginData.writer_password} onChange={handleChange} name ="writer_password" type="password" placeholder="Password" />
<Button onClick={submitForm} variant="success me-5" type="submit">Login
</Button>
);
}
export default TeacherLogin;
here is my django code:
@csrf_exempt
def WriterLoginDetails(request):
writer_email = request.POST['writer_email']
writer_password = request.POST['writer_password']
writerData = models.Writer.objects.get(writer_email = writer_email, writer_password = writer_password)
if writerData:
print('data found')
return JsonResponse({'bool':True})
else:
print('no data found')
return JsonResponse({'bool':False})
I have tried to console it in browser and even in network but I am not getting anything