mad_alien

flask_sqlite3_test.py

Jun 6th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | None | 0 0
  1. import sqlite3
  2. from flask import Flask
  3. from jinja2 import Template
  4. app = Flask(__name__)
  5.  
  6. @app.route('/resistance')
  7. def What_the_fuck_am_I_doing():
  8.     con=sqlite3.connect("local_store\\test.db")
  9.     con.isolation_level= None
  10.     cur=con.cursor()
  11.     cur.execute("select * from resistance")
  12.     #resistance is an sql table with two fields, an ID and a name
  13.     allnames=cur.fetchall()
  14.     print (allnames)
  15.     t = Template("<HTML><table><CAPTION>Fighters</CAPTION><TR> <TH>Number</TH><TH>Name</TH></TR> {%for item in items%} <TR> <TD> {{item[0]}} </TD> <TD>{{item[1]}} </TD> <TR> {% endfor %} </HTML>" )
  16.     cur.close()
  17.     print (t.render(items=allnames))
  18.     return t.render(items=allnames)
  19.    
  20. @app.route('/')
  21. def hello_world():
  22.     return ("<HTML>OH HAI!</HTML>")
  23.  
  24. if __name__ == '__main__':
  25.     app.run(debug = True)
Advertisement
Add Comment
Please, Sign In to add comment