我正在学习 django rest 框架。我想在 JSON 中获取作者全名而不是 id,下面是GET request,有没有办法?Articles从管理站点创建。我试图在前端获得价值article.author
[
{
"id": 1,
"article_title": "Premier League",
"description": "The Premier League is the top level of the English football league system. Contested by 20 clubs, it operates on a system of promotion and relegation with the English Football League. The Premier League is a corporation in which the member clubs act as shareholders.",
"created_at": "2019-10-02T08:59:24.883450Z",
"author": 1
},
{
"id": 2,
"article_title": "Cricket in England",
"description": "Cricket is one of the most popular sports in England, and has been played since the 16th century. Marylebone Cricket Club, based at Lord's, developed the modern rules of play and conduct.",
"created_at": "2019-10-02T08:59:57.075912Z",
"author": 2
},
]
反应组件的渲染功能。article.author_id给出空白并将article.author_id作者显示id为integer. 我应该返回什么来显示作者全名?
render() {
return (
<Fragment>
<h2>Articles</h2>
<div >
{
this.props.articles.map(article => (
<div className="card" key={article.id}>
<div className="card-body">
<div className="card-title"> <b>{article.article_title}</b></div>
<div className="card-text"> {article.description}</div>
<div> Author: {article.author_id}</div>
<div className="card-footer text-muted"> Created date: {article.created_at}</div>
</div>
<br></br>
</div>
))
}
</div>
</Fragment>
)
}
慕雪6442864
慕姐4208626
相关分类