简体   繁体   English

django - ajax - 从 jquery/ajax 调用 python function

[英]django - ajax - call python function from jquery/ajax

I'm working with Django to create a small website.我正在与 Django 合作创建一个小型网站。 in this project, I have some DateTime fields.在这个项目中,我有一些 DateTime 字段。 I would use ajax (via another button) to set up the UTC date keeping in mind the solar time and daylight saving time.我会使用 ajax(通过另一个按钮)设置 UTC 日期,同时牢记太阳时和夏令时。 I created a python function which computes the hour shift.我创建了一个 python function 来计算小时班次。 I would recall that function in the ajax code.我会记得 ajax 代码中的 function。 How can I do it?我该怎么做?

You have not added full code.您尚未添加完整代码。 in django you can if the request is ajax or not with this method is_ajax在 django 中,如果请求是 ajax,您可以使用此方法is_ajax

You can send payload as json and grab it from request您可以将有效载荷作为 json 发送并从request中获取

def example_ajax(request):
   if request.is_ajax():
       # some thing here
   return JsonResponse(A DICT GOES GOEST THERE)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM