与在模板中显示数据相关的问题

时间:2013-05-31 13:46:31

标签: django django-models django-forms django-templates django-views

models.py

class ReportType(models.Model):
    report = models.ForeignKey(Report)
    title = models.CharField('Incident Type', max_length=200)

    def __unicode__(self):
        return self.title

views.py

def where(request):
    user=request.user
    try:
        report = Report.objects.get(user=user.id)
    except:
        report = None
    reporttype = ReportType.objects.all()
        .          .        .
        .          .        .
    return render(request, 'incident/where.html',
        {
            'newreport_menu': True,
            'reporttype':reporttype
    })

它以这种形式[<ReportType: Bike parking>, <ReportType: car parking>]给我输出。如何显示像“自行车停放,停车场”这样的值。

1 个答案:

答案 0 :(得分:2)

使用for模板标记

{% for rt in reporttype %}
    {{ rt.title }}
{% endfor %}