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!
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With