I am using Python Tools for Visual Studio (Python 3 and django 1.6) and trying to access data from a table like this:
from django.http import HttpResponse
from django.template import Template, Context
from ticket.models import Task
def ticket_listing(request):
objects = Task.objects.all().order_by('-due_date')
template = Template('{%for elem in objects %} {{elem}}<br/> {% endfor %}')
context = Context({'objects', objects})
return HttpResponse(template.render(context))
The problem is that after Task, objects does not appear in the suggestions and it seems that it is not available. Why? If I run this code I get an empty template... There is entries in the database (3 rows) I have checked.
There is a typo in code but it doesn't make a TypeError
... You have created a set instead of a dictionary to pass to the template. Django doesn't complain since it is an iterable and there is no type checking.
>>> {1, 2}
set([1, 2])
>>> {1: 2}
{1: 2}
You just have to replace the wrong line by:
context = Context({'objects': objects})