I have two concerns here. I am trying to retrieve data from django which contains images and contents. My first concern is whether using "Content-Type": "application/json" is right. The last and major problem is am getting: TypeError: get() missing 1 required positional argument: 'pk'. What could be the issue? Below is the code:
import React, { useEffect, useState} from 'react'
import axios from 'axios'
const GetPostData = () => {
const [postState, setPostState] = useState({
loading: true,
posts: null
})
const config = {
headers: {
"Content-Type": "application/json",
Authorization: `JWT ${localStorage.getItem("access")}`,
Accept: "application/json",
},
};
useEffect(()=> {
const res = axios.get(
`${process.env.REACT_APP_API_URL}/api/list/PostView/`,
config
);
const allPosts = res.data
setPostState({loading: false, posts: allPosts})
console.log(res.data)
}, [setPostState])
return (
<div className='container'>
<h1>Latest Posts</h1>
<div>
</div>
</div>
)
}
export default GetPostData