'ProgrammingError at /user_booking not all arguments converted during bytes formatting
The idea is to display user's booking information like booking_name, package etc. I am fetching the data from database in my views.py like this.
def user_booking(request):
id = request.session['u_id']
booking_data = Booking.objects.raw('select * from booking WHERE id = %s',id)
return render(request,'user_booking.html',{'view_data':booking_data})
Now in user_booking.html is displaying data. I have used a proper template to display data in tabular format. Problem is when some data is returned from data base it works perfect. When there is a query for which no data can be found the page breaks and shows
"ProgrammingError at /user_booking not all arguments converted during bytes formatting"
Instead of all the formatting I resorted to basic code which looks like this
<html>
{% for b in view_data %}
{{b.b_name}}
{% endfor %}
</html>
It gives me the name "ajay" as output and does not break the page, also note that record for ajay's ID is present in my database. Now if ID is changed and then I refresh the lage again it gives me error.
What I am trying to do is if there is any data coming from the database then display it otherwise just display "no data here" msg.
How do I achieve it?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
