你好,我想用和添加评论。我将发送一个POST请求,并使用flask.api捕获注释文本。但是,我从服务器日志中收到以下错误:
db.execute(query, (owner, postid, flask.request.json["comment"]))
TypeError: 'NoneType' object is not subscriptable
我试图通过单击“提交”按钮来获取评论:
<form id="comment-form">
<input type="text" name="comment"/>
<input type="submit" value="Submit" onClick={this.handleChange} />
</form>
然后,我将使用python从flack API中获取值并将其插入数据库:
query = "INSERT INTO comments(commentid, owner, postid, text, created) VALUES(NULL, ?, ?, ?, DATETIME('now'))"
db.execute(query, (owner, postid, flask.request.json["comment"]))
然后我打印出以下内容,发现两者都是空的。
test whatever is in flask.request.json: None
test whatever is in flask.request.form: ImmutableMultiDict([])
这是我的POST请求:
handleChange(event) {
event.preventDefault();
console.log(this.props.url)
fetch(this.props.url, {method: 'POST'})
.then((response)=>{
return response.json();
})
.then((data) => {
this.setState({
comments: this.state.comments.concat(data)
});
})
.catch(error => console.log(error));
}