1

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-->

This prints out:

Tld object (1)

Tld object (2)

instead of the value e.g. websiteabc.com

What am I doing wrong?

Thanks

2 Answers 2

1

You have to implement __str__ in your model if you want to render a model instance like this

class Tld(models.Model):
    def __str__(self):
        # return something meaningful here like self.some_attribute

Or you have to explicitly use an attribute in template like this

 {{ authdomain.some_attribute }}

Otherwise python does not know how to get something meaningful out of an object to show.

Sign up to request clarification or add additional context in comments.

Comments

0

It's because you are trying to display the whole object, not the value.

You need to replace

{{ notauthdomain }}

with

{{ notauthdomain.name }} 

replace 'name' with the field name of your value - websiteabc.com

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.