'numpy.float64'对象没有Django属性'translate'

时间:2016-05-25 13:32:17

标签: python mysql django numpy django-queryset

您好我正在使用Django和MySQL。当我从MySQL数据库创建一个查询集并尝试操作它以将其打印到屏幕时,我收到以下错误:

'numpy.float64' object has no attribute 'translate'

这从未发生过,但我最近改变了我的电脑。

它出现在这一行:

for user in users: 

这是函数的代码:

def search(request):
    error = False
    if 'first_name' in request.GET and 'last_name' in request.GET:
        first_name, last_name, location = request.GET['first_name'], request.GET['last_name'], request.GET['location']
        search_query = SearchQuery(date=datetime.datetime.now(),first_name=first_name,last_name=last_name,location=location)
        search_query.save()
        if not first_name or not last_name or not location:
            error = True
            return render(request, 'version_1/search_form.html', {'error': error})
        lat, lon = get_coordinates(location)
        users = User.objects.raw('SELECT *, 69.0 * DEGREES(ACOS(COS(RADIANS(latitude))\
     * COS(RADIANS(%s))\
     * COS(RADIANS(longitude) - RADIANS(%s))\
     + SIN(RADIANS(latitude))\
     * SIN(RADIANS(%s)))) AS distance\
    print users
    for user in users:
        print "here"
        print user
        user.win_rate = calc_win_rate(user.wins, user.losses)
        user.address = user.address.split('\n')[-1]
        try:
            user.rating = (calc_win_rate(user.wins, user.losses)/100.0)**2*10
        except: 
            user.rating = -1
        amended_users.append(user)
    users = sorted(amended_users, key=lambda user: user.win_rate, reverse=True)
    return render(request, 'version_1/search_form.html', {'users': users})

关于可能出现什么问题的任何想法?

0 个答案:

没有答案