I’ve been trying for hours, and i can’t seem to get data from mysql to django. i’ve checked everything, views, urls, the html files, admin etc.
I have a submission in 5 hours so it’ll be great help if i chould get some help
i Tried changing function names, changing the views, the admin.py. Looked up for hours but couldnt find anything
class Bus(models.Model):
name = models.CharField(max_length=50)
bus_no = models.CharField(max_length=10, primary_key=True)
class Meta:
db_table = 'bus'
def bus_detail(request):
# Retrieve all buses with bus_no ranging from 1 to 7
buses = Bus.objects.filter(bus_no__range=(1, 7))
# Pass the retrieved buses to the template context
return render(request, 'bus-timings.html', {'buses': buses})
<table>
<thead>
<tr>
<th>Bus Name</th>
<th>Bus Number</th>
</tr>
</thead>
<tbody>
<!-- Loop through each bus and display its details -->
{% for bus in bus %}
<tr>
<td>{{ bus.name }}</td>
<td>{{ bus.bus_no }}</td>
</tr>
{% endfor %}
</tbody>
</table>
New contributor
V A is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.