我正在尝试将post数据从react发送到Django,但是该数据未附加到post对象。我的react代码看起来像这样:
class Homepage extends React.Component {
createProject() {
axios({
method: "post",
url: "localhost:8000/createProject/,
headers: { "Content-Type": "application/json" },
data: { name: "projectname" },
})
}
render() {
return <div onClick={this.createProject}></div>
}
urls.py
urlpatterns = [
path( "createProject/", views.createProject ),
]
views.py
def createProject( requests ):
print( requests.POST )
return JsonResponse({"this returns": "just fine"})
views.py中print( requests.POST )
的输出:
<QueryDict: {}>
如果有关系,我在django函数上使用csrf_exempt,因为没有部署计划。
谢谢!
答案 0 :(得分:0)
尝试在视图中打印
print(request.get.POST('data'))