sid = request.POST.get['stuid'] TypeError: 'method' object is not subscriptable

Viewed 25

this is my view code in django for saving data and sid is for editing the User id data if it not blank then it will be edited else it is store as a new id .

def save_data(request):
    if request.method == 'POST':
        form = StudentRegistration(request.POST)
        if form.is_valid():
            sid = request.POST.get['stuid']
            name = request.POST['name']
            email = request.POST['email']
            password = request.POST['password']
            if (sid == ''):
                usr = User(name=name,email=email,password=password)
            else:
                usr = User(id = sid ,name= name,email= email, password= password)
            usr.save()
            stud = User.objects.values()
            print(stud)
            student_data = list(stud)
            return JsonResponse({'status':'Save','student_data':student_data})
        else:
            return JsonResponse({'status':0})
2 Answers

get is a method, so the brackets to invoke that method should be parentheses:

 request.POST.get('stuid')

every method, so the brackets to invoke that method should be parentheses: requestenter code here.POST.get('your_id')

Related