Opened 15 years ago

Closed 15 years ago

#11657 closed (invalid)

Displaying Data from database(MySql)

Reported by: sumeet Owned by: nobody
Component: Uncategorized Version: 1.1
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I am new in using Django and I want to display multiple rows from the database in my html page. I have made the necessary entries in views.py, urls.py and in the html file. The following is my code :

Code in views.py

def process(request):

data=[]
db = MySQLdb.connect(user='root', db='books', passwd='admin', host='localhost')
cursor = db.cursor()
cursor.execute('SELECT * FROM sms_recieved_dummy')
data=cursor.fetchall()
db.close()
return render_to_response('process.html', {'datas': data})

Code in process.html :

{% if datas %}

<ul>

{% for d in datas %}
<li>{{ d }} </li>
{% endfor %}

</ul><br>

{% endif %}

Here the problem is ... I want to display all the column data from each row from the database individually in my html in table format. How can i do that ?

Change History (1)

comment:1 by anonymous, 15 years ago

Resolution: invalid
Status: newclosed

It's not a forum ! You can report bugs here, not asking questions. Anyway you should use Django ORM instead of MySQLdb library. Ask on django irc channel or mailing list.

Note: See TracTickets for help on using tickets.
Back to Top