Reputation: 7747
I request a page that calls the following view:
views.py:
from django.http import HttpResponse
from django.template import Context, loader
from mainsite.models import Courses
def individualCourse(request, course_short):
c = Courses.objects.get(short=course_short)
t = loader.get_template('course.html')
cont = Context({
'course_short': c.short,
'course_title': c.title,
'course_start': c.startDate,
'course_end': c.endDate,
'course_fees': c.fees,
'course_description': c.description,
'course_content': c.content
})
return HttpResponse(t.render(cont))
models.py:
from django.db import models
class Courses(models.Model):
title = models.CharField(max_length=200)
short = models.CharField(max_length=5)
startDate = models.DateField(auto_now=False, auto_now_add=False)
endDate = models.DateField(auto_now=False, auto_now_add=False)
fees = models.IntegerField()
description = models.TextField()
content = models.TextField()
def __unicode__(self):
return self.title, self.short, self.startDate, self.endDate, self.fees, self.description, self.content
course.html:
<html>
<head><title>Course</title></head>
<body>
<p>{{ course_title }}</p>
<p>{{ course_short }}</p>
<p>{{ course_start }}</p>
<p>{{ course_end }}</p>
<p>{{ course_fees }}</p>
<p>{{ course_description }}</p>
<p>{{ course_content }}</p>
</body>
</html>
I want it to display all the details for that particular course, but when it renders on the page, it only displays the title of the requested course. Does anyone know what I'm doing wrong?
Upvotes: 0
Views: 78
Reputation: 513
try this one i dont know the return type specifier for a date field, it needs some correction but should look something like this
def __unicode__(self):
return u'%s (%s %s %s %d %s %s %s)' % (self.title, self.short, self.startDate, self.endDate, self.fees, self.description, self.content)
Upvotes: 2