On 14 Sty, 23:01, Ken <ken.kyhu...@gmail.com> wrote: > Newb question here. How do I pass raw sql results to my template? > The sql results contains a two column queryset with several rows . > > Below doesn't work. How do I make this work? Do I need to parse the > results into an array and then pass to the template? > > IN THE VIEW: > cursor = connection.cursor() > cursor.execute("query goes here") > results = cursor.fetchall() > > return render_to_response('template.html', {'results': results}) > > IN THE TEMPLATE: > {% for result in results %} > <br>{{ result[0] }} is a big {{ result[1] }} > {% endfor %}
I haven't checked this in shell, but it looks to be correct, except that you should write: {{ result.0 }} instead of {{ result [0] }} Here's the relevant doc section: http://docs.djangoproject.com/en/1.1/topics/templates/#variables -- Tomasz Zielinski http://pyconsultant.eu
-- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.