In Django, I'm having trouble getting the id from HTML; the error is: ( Field "id" expected a number but got )

When the user selects the translator name, I want to access the selected translator in Django by the id and store the information in an appointment table in the database, but there is an error when he tries to mach the id the error is: Field 'id' expected a number but got ''.

HtML code:

 <section style="margin-top: 10%;">       
    <form method="POST" action="/waite" >
        {% csrf_token %} 
        <select id="translator" name="translator">
        {% for i in pro %}
             <option value="{{ }}"> {{ }}</option>
        {% endfor %}
      <button type="submit">Send request</button>  


in django

def waitePage(request):
        if request.method == 'POST':
            id = request.POST.get("translator")
            translator = Manager.objects.get(user_id=id)
            translatorName= #get the name of the translator
            translatorID= #get the id of the translator

            current_user  = request.user #to get the user
            current_userId = #for storing user id
            customer = Customer.objects.get(id=current_userId) #to get the info of translator

            appointment = Appointment.objects.create(
            customerID=customerID, translatorID=translatorID, accepted=False,)
            return render(request,'waitePage.html')

The error comes from:

   translator = Manager.objects.get(user_id=id) 

Do you guys have any idea how I can solve it?

Do you guys have any idea how I can solve it?

Instead of this:

<form method="POST" action="/waite" >

try this one:

<form method="POST" action="{% url 'waitePage' %}">

Django use Jinja templating, that may be the reason why you don't get id.

Back to Top