I'm making website using django and react. I have already set up backend in django and tested it using postman, everything works fine but when I'm doing exact same thing using react i'm getting 400 error.
Tried to do it like that:
To avoid any other error I used static data in this example
export default function MakePost(){
const [userID, setUserID] = useState(1);
const [text, setText] = useState('');
const submit = async e => {
e.preventDefault();
const requestOptions = {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({id: 1, text: 'some text'})
}
fetch('http://localhost:8000/api/make-post/', requestOptions)
.then(response => {
console.log(response)
if(response.ok){
return response.json();
}
});
window.location.reload();
}