Reputation: 3
Django Template not displaying model data, showing blank page ...Have a look at it:
models.py
class appointment(models.Model):
patient_name1= models.ForeignKey('identity')
appoint_date= models.DateTimeField('Appoinment time and date')
patient_info= models.TextField()
fees= models.CharField('Fees',max_length=100,blank=True)
class Meta:
verbose_name = 'Appointment Detail'
verbose_name_plural = 'Appoinment Details'
ordering = ['appoint_date']
def __str__(self):
return '%s (%s)' % (self. patient_name1, self.appoint_date)
views.py
from django.shortcuts import render
from .models import identity, appointment
def index(request):
return render(request, 'appoint/index.html')
def appointment_list(request):
Appointments = appointment.objects.all()
context = {'Appointments': Appointments}
return render(request, 'appoint/appointment_list.html', context)
appointment_list.html
<p>{{Appointments.patient_name1}}</p>
urls.py
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^appointment_list/$', views.appointment_list, name='appointment_list'),
url(r'^aboutme/$', views.aboutme, name='about_us'),
url(r'^contact/$', views.contact, name='contact_us'),
url(r'^apply_appoint/$', views.apply_appoint, name='apply_appoint'),
]
please help me i am new to Django 1.9
Upvotes: 0
Views: 1997
Reputation: 1318
Appointments
is a list of model objects you need to loop over them in template
like this:
<p>
{% for object in Appointments %}
{{ object.patient_name1 }} , {{ object.appoint_date }}
{% endfor %}
</p>
Upvotes: 1
Reputation: 37934
you need to iterate over the queryset and then access object's attribute:
<p>
{% for appointment in Appointments %}
{{ appointment.patient_name1 }}
{% endfor %}
</p>
Appointments
is a queryset which is a list of instances of Appointment class.
and you need to name your classes with Capital letter btw. Normally objects are in lowercase and class names begin with Capital letter.
Upvotes: 1