I have the following code:
settings.py
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'tectcom', 'USER': 'test', 'PASSWORD': '***146***', 'HOST': '', 'PORT': '', }, 'cdr': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'ast', 'USER': '123', 'PASSWORD': '654', 'HOST': '', 'PORT': '', }
views.py
def cdr_user(request): cursor = connections['cdr'].cursor() calls = cursor.execute('SELECT * FROM cdr') return render_to_response("cdr_user.html", {'result':calls }, context_instance=RequestContext(request))
cdr_user.html
{% for res in result %} {{ res.billsec }}<br /> {% endfor %}
The table is like that:
+-------------+--------------+------+-----+---------------------+-------+ | Field | Type | Null | Key | Default | Extra | +-------------+--------------+------+-----+---------------------+-------+ | calldate | datetime | NO | MUL | 0000-00-00 00:00:00 | | | clid | varchar(80) | NO | | | | | src | varchar(80) | NO | | | | | dst | varchar(80) | NO | MUL | | | | dcontext | varchar(80) | NO | | | | | channel | varchar(80) | NO | | | | | dstchannel | varchar(80) | NO | | | | | lastapp | varchar(80) | NO | | | | | lastdata | varchar(80) | NO | | | | | duration | int(11) | NO | | 0 | | | billsec | int(11) | NO | | 0 | | | disposition | varchar(45) | NO | | | | | amaflags | int(11) | NO | | 0 | | | accountcode | varchar(20) | NO | MUL | | | | userfield | varchar(255) | NO | | | | | uniqueid | varchar(32) | NO | | | | | linkedid | varchar(32) | NO | | | | | sequence | varchar(32) | NO | | | | | peeraccount | varchar(32) | NO | | | | +-------------+--------------+------+-----+---------------------+-------+
The problem is that I get a "Exception Value: 'long' object is not iterable"
How do I make result iterable to show it in my template? I've seen https://docs.djangoproject.com/en/dev/topics/db/sql/ and also other documentation, but I'm still lost in the code.
Thank you.