'Rendering database data to browser in Django
I am having difficulties with showing database data in browser with Django. I have, for show my issue, just one date in my database. When I go to the Django Shell I got this:
>>>from events.models import Event
>>>Event.objects.all()
<QuerySet [SuperBowl22]
My models.py has:
from unicodedata import name
from django.db import models
from django.forms import DateTimeField
class Event(models.Model):
name = models.CharField('Name´s event', max_length=120)
timeEvent = models.DateTimeField ('Event´s date')
seat_position = models.ForeignKey(Seat_position, blank=True, null=True, on_delete=models.CASCADE)
fanatic = models.OneToOneField(EPS, blank=True, null=True, on_delete=models.CASCADE)
def __repr__(self):
return self.nombre
My views.py has:
from .models import Event
from token import RIGHTSHIFTEQUAL
from django.shortcuts import render
from django.http import HttpResponse
from datetime import date
def all_events(request):
event_list = Event.objects.all()
return render(request,
'events/event_list.html',
{'event_list': event_list}
)
My event_list.HTML has:
{% extends 'base.html' %}
{% block title %}Showing database info{% endblock title %}
{% block content %}
<h1>Result(s) of database consultation:</h1>
<ul>
{% for events in event_list %}
<li>{{ event.name }}</li>
{% endfor %}
</ul>
{% endblock content %}
I run the runserver with no errors and go to http://127.0.0.1:8000/events/ and the browser shows:
Result(s) of database consultation:
.
- Why the HTML is not showing <QuerySet [SuperBowl22] or it equivalent?
- Have I some typo or any small mistake?
- The django shell shows a correct result of the Event.objects.all(). Why there is no result in the web page?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|