I agree with previous posts.

It might also be worthwhile to simplify your code to avoid unneeded 
variables:

        details=Details(
            name=requests.POST.get('name'), 
            roof_age=requests.POST.get('roof_age'), 
            email=requests.POST.get('email'),
            phone=requests.POST.get('phone'), 
            address=requests.POST.get('address'),
            monthly_bill=requests.POST.get('monthly_bill'), 
            HOA=requests.POST.get('HOA'), 
            battery=requests.POST.get('battery'), 
            foundation=requests.POST.get('foundation'), 
            roof_type=requests.POST.get('roof_type'),
            availability=requests.POST.get('availability'),
            bill=requests.POST.get('bill')
        )
        print(details)
        details.clean()
        details.save()
        print("The data has been saved to db")

On Sunday, 18 September 2022 at 00:25:36 UTC+2 Ryan Nowakowski wrote:

>
> On Sat, Sep 17, 2022 at 11:48:06PM +0530, Nishant Sagar wrote: 
> > While saving the values to the data to the database I'm getting this 
> Field 
> > 'roof_age' expected a number but got ('1',) 
> > 
> > How can I resolve this? 
> > Here is my views.py file 
> > def form(requests): 
> > if requests.method == 'POST': 
> > name=requests.POST['name'], 
> > # roof_age= requests.POST['roof_age'], 
> > roof_age= int(requests.POST.get('roof_age')), 
>
> You have an errant comma at the end of the line which makes roof_age a 
> tuple. Get rid of the comma. 
>
> Also, I agree with the other reply that you should probably be using a 
> Form[1] to handle POST input. 
>
> [1] https://docs.djangoproject.com/en/4.1/topics/forms/ 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/91aa5b2c-4f4d-45d9-858b-872b536b719an%40googlegroups.com.

Reply via email to