Home > Blockchain >  unable to pass a variable in pyrebase
unable to pass a variable in pyrebase

Time:11-15

I am trying to read data from the firebase real-time db using pyrebase. when attempting to pass a variable instead of a string, I don't get a value. When a string is passed the value is successfully retrieved.

Works

def calculate_score(request,*args, **kwargs):    
    account_type = request.POST.get('atype', False)
    db_target = database.child('PMS').child('Indie').child('Cornerstone').get().val()

Doesn't work:

def calculate_score(request,*args, **kwargs):    
    account_type = request.POST.get('atype', False)
    db_target = database.child('PMS').child('Indie').child(account_type).get().val()

CodePudding user response:

The child() function only accepts a string, but that can be either a literal string (like in your first snippet) or a string variable. If the second snippet doesn't work, it's most likely that the account_type is not a string.

I'm not a Python expert, but you'll want to see what type request.POST.get('atype', False) returns and convert that to a string of needed.

CodePudding user response:

I got the following response.

https://i.stack.imgur.com/BJ7bp.png

So what I am passing is definitely a string.

ie. Also tried str(account_type) and passing as a dict

  • Related