Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'instancemethod' object has no attribute '__getitem__'

I keep getting this error:

TypeError: 'instancemethod' object has no attribute '__getitem__'

With my particular view on a django site I am playing around with. I have no idea why but I have a feeling it might be related to the way I am retrieving a specific object from a model.

The error occurs here:

def myview(request):
    if request.method == 'POST':
        tel = request.POST.get['tel_number']
        person = get_object_or_404(Employee,phone_number=tel) # HERE

I have an Employee model with phone_number as a CharField as such:

class Employee(models.Model):
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30)
    phone_number = models.CharField(max_length=10)

The request.POST data is sent from an android application. All I want to do is to retrieve an Employee object that has a particular phone_number value.

Thank you!

like image 415
bluecat Avatar asked Mar 27 '13 18:03

bluecat


1 Answers

The problem is in this line tel = request.POST.get['tel_number']. If you are using .get you should pass the key as an argument:

tel = request.POST.get('tel_number') # if key is not present by default it will return None

Otherwise you can do this:

tel = request.POST['tel_number'] # raise KeyError Exception if key is not present in dict
like image 199
Aamir Rind Avatar answered Sep 21 '22 21:09

Aamir Rind