Opened 7 years ago

Closed 7 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: UI/UX:

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 Changed 7 years ago by anonymous

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
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