display vakues in table in template

6 views
Skip to first unread message

leb dev

unread,
Sep 6, 2019, 3:11:00 AM9/6/19
to Django users
i have a django project that is connected to SQL Server  i tried to retrieve data from the database.

if i try to display all the data it run correct and display all the values.

but if i try to display the data in an **html table** it doesn't display anything.

views.py
=======

    def connect(request):
        conn = pyodbc.connect(
            'Driver={ODBC Driver 17 for SQL Server};'
            'Server=DESKTOP-LPD1575\\SQLEXPRESS;'
            'Database=testDB;'
            'UID=test;'
            'PWD=test;'
    
        )
    
        cursor = conn.cursor()
        c = cursor.execute('SELECT * FROM Artist')
        return render (request,'connect.html',{"c":c})

 
connect.html
========


 <table align = "center">
        <tr align="center">
            <th>ID</th>
            <th>FolderNumber</th>
            <th>Title</th>
           
        </tr>
       {% for row in c %}
        <tr align="center">
            {% for item in row %}
                <td>{{ item }}</td>
            {% endfor %}
        </tr>
    {% endfor %}
    </table> 

anyone can help me?
Reply all
Reply to author
Forward
0 new messages