模板呈现:
Hello, [<Student: Bob Frediricko>]. How are you?
但我希望它呈现:
Hello, Bob. How are you?
视图执行此操作:
q = Student.objects.filter(pk=1)
for f in survey_formset:
f.helper.layout = Layout(HTML("""
Hello, {{ q }}. How are you?
"""))
学生模特有......
def __unicode__ (self):
return smart_unicode(self.first_name+" "+self.last_name)
感谢您的帮助:]
答案 0 :(得分:2)
filter
返回一个列表,这是您在渲染模板中看到的字符串化结果。
请改为尝试:
q = Student.objects.filter(pk=1)[0]
或者更好,因为你是通过pk选择的(这是唯一的):
q = Student.objects.get(pk=1)