D
D
dustik2013-05-20 08:36:01
Django
dustik, 2013-05-20 08:36:01

Django. Working with data from the database and displaying it in a template?

Hello.
I ask you to reason with an unreasonable newbie in django and python.
The crux of the matter is as follows.
There is a hypothetical query that is processed in the MySQL DBMS:
a054d2cb6b6059f501696e3178344306.jpg
The text of the same query is included in the view: The
54a1a25f0ab609b295767447eaac83f3.jpg
returned data is embedded in the template:
829c6ebe8ce10f3283c909de913ca198.jpg
When I open the page, I get an escape sequence and I don’t understand what to do with this result set in the future
6328bf74e00338d6493066e0391445ec.jpg
From reading books, to the current moment in time, there is no positive, because in the head now from the received dose of information is porridge and it takes some time to rethink what has been read and line up all the material on the shelves.
I ask you to give recommendations on how to switch from Unicode strings to a normal human-oriented display and how it is possible to access only the field with the name or the field with the number from this result set.
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Artur Bordenyuk, 2013-05-20
@dustik

There is information that the row variable is a tuple.
Try

{{ row.NameDocumentFull }}
<br>
{{ row.QDNumSerial }}

Y
Yuri Shikanov, 2013-05-20
@dizballanze

Why don't you use an ORM?

M
marazm, 2013-06-05
@marazm

You are typing dict. And there is nothing surprising about what is printed in ascii. If you output separate lines, they will be decoded in utf.
And to access the list index in django templates use "."
In principle, everything has already been painted above.

M
Michael, 2013-07-20
@MikeVL

Try like this:

    conn.execute("SQL ...")
    rows = conn.fetchall()
    keys = [t[0] for t in conn.description]
    advert_set = [dict(zip(keys, row)) for row in rows]

In the template like this:
{% for row in advert_set %}
{{ row.field_name }}
{% endfor %}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question