Blank page due to "for template tag" in Django

Viewed 77

My web page was working fine until I added {% for %} in my template file.

This is my home.html file

<body>
<div>
    <div>
{% if not status %}
            <a href="/gmailAuthenticate" onclick="gmailAuthenticate()" title="Google">Google</a>
{% else %}
{% for item in contexto %}
<p>Your are verified</p>
            <form id="myform" method="post" action="{% url 'logout' id=item.id %}/?next={{request.path }}">
    {% csrf_token %}
    <input type="hidden" name="name" value="value" />
    <a onclick="document.getElementById('myform').submit();">disconnect</a>
</form>
{% endfor %}
{% endif %}
    </div>

</div>
</body>

And this is my home function

def home(request):
    status = True
    contexto = CredentialsModel.objects.all()

    if not request.user.is_authenticated:
        return HttpResponseRedirect('admin')

    storage = DjangoORMStorage(CredentialsModel, 'id', request.user, 'credential')
    credential = storage.get()
    try:
        access_token = credential.access_token
        resp, cont = Http().request("https://www.googleapis.com/auth/gmail.readonly",
                                    headers={'Host': 'www.googleapis.com',
                                            'Authorization': access_token})
    except:
        status = False
        print('Not Found')

    return render(request, 'index.html', {'status': status})

I´ve checked my errors.log file, but nothing is displayed

2 Answers

You're not providing the contexto queryset to the template context:

return render(request, 'index.html', {'status': status, 'contexto': contexto})

You have to pass the variable contexto to your template.

It will be something like:

return render(request, 'index.html', {'status': status, 'contexto': contexto} )
Related