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

Time:09-16

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})

CodePudding user response:

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

 request.POST.get('stuid')

CodePudding user response:

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

  • Related