希望是一个简单的......
views.py
def View(request):
queryset = Example.objects.all()
for obj in queryset :
obj.x = 'String attribute added to model instance.'
context = {'queryset ': queryset }
return render(request, 'app/template.html', context=context)
template.html
{% for obj in queryset.all %}
{{ obj.x }}
{% endfor %}
根据Stefano Contini的article,这应该可行,但在我的例子{{obj.x}}中并没有完成这个字符串。我做错了什么?
答案 0 :(得分:0)
{%for queryj.all%}中的obj不正确
{%对于queryset%中的obj}是正确的
感谢@Daniel Roseman提出回答问题的问题