In your views.py,you can code like this:
1 ImportMySQLdb2 defIndex (Request):3conn=MySQLdb.connect (4host='127.0.0.1',5port=3306,6User='Root',7Passwd='Root',8db='Pythonweb',9charset='UTF8',#must be consistent with the code when the database is establishedTen One ) ACursor=conn.cursor ()#Defining Cursors -Cursor.execute ("SELECT * from Firstapp_article") -results=Cursor.fetchmany () the -articles=[] - forResultinchResults: - Articles.append ( + { - #this is associated with a table that is defined in the database + #result[0] as ID A 'title': result[1], at 'content': result[2], - ' views': result[3], - 'likes': result[4], - 'Createtime': result[5], - 'Editors_choice': result[6], - 'cover': result[7], in 'Url_image': result[8], - } to + ) -context={} thecontext['Articles']=Articles * returnRender (Request,'index.html', context)
The interaction between SQL and DB in Django--Non-ORM