Models.py:如何从模型对象模板标签Django模型字段值
class Discussion(models.Model):
version = models.TextField(blank=True)
team = models.TextField(blank=True)
project = models.TextField(blank=True)
notes = models.TextField(db_column='Notes', blank=True) # Field name made lowercase.
s = models.TextField(blank=True)
send_mail_to = models.TextField(blank=True)
send_mail_cc = models.TextField(blank=True)
date = models.DateTimeField(null=True, blank=True)
class Meta:
db_table = u'discussion'
views.py:
p=Discussion.objects.filter(version=m2)
return render_to_response('report/t2',{"p":p})
模板(HTML):
<tr>
<td width="20%" class="scratchblackfont12">Release Name :</td>
<td><div style="overflow:auto"><input name="Release Name (if any):" autocomplete="on" type="text" class="scratchsearchfield" elname="defaultFocus" id="r1" value="{{p.version}}" READONLY multiline="true" ></div>
</td>
</tr>
但模板显示Nothing。请帮助我解决此问题。我想从模板对象中获取模型字段值。
好的回答@rolling stone。我完全错过了他使用过滤器而不是get的事实。我会停止回答这么晚的问题:) – Brandon
@Brandon哈哈,你应该看到我在深夜给出的一些其他答案! –