views.py
@login_required
def ManageDomain(request):
AssocNotAuthDomains = Tld.objects.filter(FKtoUser_id=request.user,auth=0)
AssocAuthDomains = Tld.objects.filter(FKtoUser_id=request.user,auth=1)
return render(request, 'site/account/template.html', {
'AssocNotAuthDomains':AssocNotAuthDomains,
'AssocAuthDomains':AssocAuthDomains
})
template.html
{% if AssocAuthDomains or AssocNotAuthDomains %}
<div class="acctDomains">
<h3 class="Titles"><img src="{% static "img/templated/acct/AuthDomainSm.png" %}" width="22" height="22" alt="Authorized Domain(s)" /> Verified Domains</h3>
<ul>
{% for authdomain in AssocAuthDomains %}
<li>{{ authdomain }}<span><a class="scan" href="/Account/PerformScan/?d={{ authdomain }}">Scan now</span></a></li>
{% endfor %}
</ul>
<h3 class="Titles"><img src="{% static "img/templated/acct/UnAuthDomain.png" %}" width="22" height="22" alt="Unverified Domain(s):" /> Unverified Domains</h3>
<ul>
{% for notauthdomain in AssocNotAuthDomains %}
<li>{{ notauthdomain }}<span><a class="scan" href="Verify Now">Verify now</span></a></li>
{% endfor %}
</ul>
</div><!--acctDomains-->
这将打印出来:
Tld object (1)
Tld object (2)
而不是值,例如websiteabc.com
我做错了什么?
谢谢
发布于 2019-03-18 02:54:47
如果要呈现这样的模型实例,则必须在模型中实现__str__
class Tld(models.Model):
def __str__(self):
# return something meaningful here like self.some_attribute
或者您必须在模板中显式使用一个属性,如下所示
{{ authdomain.some_attribute }}
否则,python不知道如何从对象中获取有意义的内容来显示。
发布于 2019-03-18 02:51:26
这是因为您试图显示整个对象,而不是值。
你需要更换
{{ notauthdomain }}
使用
{{ notauthdomain.name }}
将' name‘替换为您的值的字段名- websiteabc.com
https://stackoverflow.com/questions/55210601
复制相似问题