Django get_total_topup()缺少1个必需的位置参数:“ request”

时间:2019-06-23 16:23:32

标签: django python-3.x

class IndexAjaxView(View):
   def get(self, request): 
      param = request.GET.get('param')

      if param == 'get_total_topup':
        return self.get_total_topup()

      return JSONResponse({}, status=404)

   def get_total_topup(self, request):
      return JSONResponse({
        'value': 'Rp.{:,.0f},-'.format(
            TopUp.objects.filter(owned_by=request.user).aggregate(Sum('amount'))['amount__sum']
       )
      })

有人可以帮助我吗?我想通过ajax获取数据,但响应为500,消息get_total_topup()缺少1个必需的位置参数:'request'

2 个答案:

答案 0 :(得分:1)

您在class Home { public featuresHome FeaturesHome { get; set; } } class featuresHome { public homePosition HomePosition { get; set; } public homeKind HomeKind { get; set; } } class homePosition { public string PositionLake { get; set; } public string PositionDowntown { get; set; } } class homeKind { public string HomeFlat { get; set; } = string.Empty; public string HomeVilla { get; set; } = string.Empty; } class Program { static List<Home> HomeList = new List<Home>(); static void Main(string[] args) { HomeList.Add(new Home()); featuresHome FeaturesHome = HomeList.Last().FeaturesHome; var property = typeof(featuresHome).GetProperty("homePosition"); property.SetValue(FeaturesHome.HomePosition.PositionLake, "Mono Lake", null); //Here there is an error } } 中的调用没有参数,但您的定义return self.get_total_topup()需要一个参数。尝试def get_total_topup(self, request)

return self.get_total_topup(request)

答案 1 :(得分:0)

您在方法调用中缺少一个位置参数。

return self.get_total_topup()

修复至

return self.get_total_topup(request)