这是我的模特:
class Claim(models.Model):
def __str__(self):
return self.claim_id
policy = models.ForeignKey(Policy);
claim_id = models.CharField(max_length=50, unique=True, db_index=True);
loss_dt = models.DateTimeField();
loss_location = models.CharField(max_length=100);
clam_stat = models.CharField(max_length=2, default='open');
cas_aia_cds_1_2 = models.CharField(max_length=50);
cas_aia_cds_3_4 = models.CharField(max_length=50);
reported_dt = models.DateTimeField();
loss_desc = models.TextField();
class Meta:
ordering = ['-loss_dt','reported_dt']
在views.py中:
def home(request):
try:
claims = m.Claim.objects.all()
claims_list = []
for c in claims:
claims_list.append(c.loss_desc)
context = RequestContext(request, {
'claim_list': claims_list
})
return render_to_response(request, 'home.html', context_instance=context)
except m.Claim.DoesNotExist:
raise Http404
我要做的是将声明对象列表发送到模板。
任何想法都将不胜感激。
答案 0 :(得分:2)
render_to_response
并未将request
作为参数。
将其移除并保持原样。