Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sqlite3
- from flask import Flask, render_template
- from werkzeug.exceptions import abort
- app = Flask(__name__)
- def get_db_connection(filename):
- conn = sqlite3.connect(filename)
- conn.row_factory = sqlite3.Row
- return conn
- @app.route('/')
- def index():
- conn = get_db_connection('database.db')
- items = conn.execute('SELECT * FROM items').fetchall()
- conn.close()
- return render_template('index.html', items=items)
- def get_item(item_id):
- conn = get_db_connection('database.db')
- item = conn.execute('SELECT * FROM items WHERE id = ?', (item_id,)).fetchone()
- conn.close()
- if item is None:
- abort(404)
- return item
- def get_positiona(company):
- conn = get_db_connection('mydatabase.db')
- item = conn.execute('SELECT * FROM documents WHERE company_to = ?', (company,)).fetchall()
- conn.close()
- return item
- @app.route('/<int:item_id>')
- def item(item_id):
- item = get_item(item_id)
- pos = get_positiona(item['company'])
- return render_template('item.html', item=item, pos=pos)
- if __name__ == '__main__':
- app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement