How to retrieve specific input field in view.py and check if it matches with Tickets() modal.py

Hello Django developer,

I want to know if the ID ticket user input matches the ID ticket from modal.py. So here’s what I did: first, I created an HTML input:

<!-- ======== Tickets ======== -->
<div class="ui selection dropdown form-inp" id="inputField">
     <input type="hidden" name="ticket"> 
      <i class="dropdown icon"></i>
       <div class="text col-form-label">Select Ticket ID</div>
       <div class="menu" id="tickets-data-box" name="ticket"></div>
</div>

And then I call it in views.py by using the name="ticket":

ticket_log = Tickets.objects.get(ticket_id = request.GET.get('ticket') )

but I got this message:

Exception Type:	DoesNotExist
Exception Value:	Tickets matching query does not exist

but when I use the same value is correct, it works

  ticket_fake = '22020233'
  test = request.GET.get('ticket') #->  '22020233'
  
  print("tickest fake" , ticket_fake )
  print("ticket input: ",  test )

ticket_log = Tickets.objects.get(ticket_id = ticket_fake)

see the below in cmd:
image

Hey there!
The .get will raise an exception if there is no object with the given filters. If you wish to handle the case that this object does not exists, you can:

  • handle the YourModelName.DoesNotExist exception on a tryexcept block;
  • use the .first method that will return None.

I recommend that you review the queryset documentation

How are you submitting this request to the server? Have you verified that in your view, request.GET.get('ticket') has what you think it has?