On Thu, Nov 22, 2012 at 2:27 PM, Nebros <markuschriste...@gmail.com> wrote:
> Hello, i know I have asked this before in another post of me, but no one > answered on it and it was not part of topic... > In fact, I did, but you ignored all my advice, didn't fix the problems I pointed out, and still present with the same issue. > > I am using pyodbc and try to give data out into my page... > > Here the part of pyodbc (and yes this works): > > views--------------------------------------------------------- > ..... > 1 conn = pyodbc.connect('DRIVER={SQL > Server};SERVER=MAURITIUS;DATABASE=baan5c;UID=***;PWD=*****') > 2 cursor = conn.cursor() > 3 cursor.execute("SELECT x.t_name, y.t_mail FROM tttaad200000 as x, > tttcmf200000 as y WHERE (x.t_name = y.t_name)") > 4 row = cursor.fetchall() > 5 > 6 return render_to_response("kundendaten.html", { 'row': row}, > context_instance=RequestContext(request)) > ..... > ----------------------------------------------------------------- > > On line number 4 you can see now, there is "row = cursor.fetchall()"... > When i give out this part now i become two outputs, (one without formatting > to see what value i become, the other have to be in a table) > > Here the parts of my website: > > Kundendaten------------------------------------- > ..... > {% block content2 %}Kundendaten{{ row }}.{% endblock %} > ..... > <tr> > <th>Name</th> > <th>Mail</th> > </tr> > {% for t_user in row %} > <tr> > <td>{{ row.t_name }}</td> > <td>{{ row.t_mail }}</td> > </tr> > {% endfor %} > Again. If you say "for t_user in row", then you iterate over the list "row", giving a variable inside the loop named "t_user" for each element in the list. You then don't actually use "t_user" inside the loop, you use "row". "row" is your list of rows, not an element in the list. This is why you get 3 empty lines in your table - there are three items in "row", but there are no attribute on "row" named "t_name" or "t_mail" - they are on the items inside "row". In fact, each item in row does not have those attributes. Lets look at what fetchall() returns: >>> c.execute("SELECT id, name from auth_group WHERE id < 4") 3L >>> c.fetchall() ((2L, u'Client Super User'), (3L, u'Helpdesk User'), (1L, u'IT User')) So, fetchall() returns a tuple of tuples. If you iterate through this in your template, then you must refer to each variable by its position - there is no "t_name" to refer to. Eg: {% for row in rows %} <tr> <td>{{ row.0 }}</td> <td>{{ row.1 }}</td> </tr> {% endfor %} Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.