目前,我使用django和ajax进行了简单的应用程序。
虽然编写了如下结构的代码,
使用ajax发送的值可以在view.py
中接收。
但是,在那之后使用条件分支中的值时,我不能。
问题的原因是什么?
ajax.html
var slot_id = 1;
$.ajax({
type:"POST",
data:{
'slot_id':slot_id,
},
views.py
if request.method == 'POST':
slot_id = request._post['slot_id']
print(slot_id) ** it can display 1**
if slot_id == 1:
print(slot_id) **it cannot display 1**
答案 0 :(得分:1)
我可以根据建议解决这个问题 view.py
if request.method == 'POST':
slot_id = int(request._post['slot_id'])
print(slot_id)
if slot_id == 1:
print(slot_id) **it can display 1**