【发布时间】:2022-01-07 04:29:36
【问题描述】:
我想在我的 Django 项目中使用 Ajax 从 JS 函数将变量传递给 python 函数。 我可以调用python函数。使用ajax方法,我知道这是因为python函数中的print函数运行。 但是如何通过这个 ajax 调用传递我的变量?我只想传递局部变量,以便它可以由 python 函数打印。
JS
function calling (){
var local = 25
$.ajax({
type:'GET',
url:'printsome/',
success: function(response){
console.log('success');
console.log(local);
},
error: function (response){
console.log('error');
}
});
}
蟒蛇
def print_some(request):
from django.http import JsonResponse
print('this python function was called')
return JsonResponse({})
【问题讨论】:
-
这个问题和 Java 有什么关系?
标签: javascript python django ajax