Skip to content

Instantly share code, notes, and snippets.

@YCF
Last active December 17, 2015 06:09
Show Gist options
  • Save YCF/5563469 to your computer and use it in GitHub Desktop.
Save YCF/5563469 to your computer and use it in GitHub Desktop.
@app.route('/', methods=['GET', 'POST'])
def demo():
conn=pymssql.connect(host='blablabla\SQLEXPRESS',user='blabla',password='123',database='x',charset='utf8')
cur=conn.cursor()
sqlquery=u"SELECT TOP 1000 [ID],[姓名],[内容] FROM demo_db"
sqlquery=sqlquery.encode("utf8")
cur.execute(sqlquery)
row=cur.fetchone()
cts = [dict(name=row[1],ct=row[2]) for row in cur.fetchall()]
for i in cts:
i['name']=i['name'].decode('utf8')
conn.close()
return render_template('demo.html',cts=cts)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment