-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
38 lines (30 loc) · 1.17 KB
/
main.py
File metadata and controls
38 lines (30 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from flask import Flask, render_template
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
## import the sqlache file
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///market.db'
# Declared db instance
db = SQLAlchemy(app)
# created db table
class Item(db.Model):
id = db.Column(db.Integer(), primary_key=True)
name = db.Column(db.String(length=30), nullable=False, unique=True)
price = db.Column(db.Integer(), nullable=False)
barcode = db.Column(db.String(length=12), nullable=False, unique=True)
description = db.Column(db.String(length=1050), nullable=False, unique=True)
def __repr__(self):
return f'Item {self.name}'
@app.route('/')
@app.route('/home')
def home_page():
return render_template('home.html')
@app.route('/market')
def market_page():
items = Item.query.all()
## use this array on items if no actual database needed
## [
## {'id': 1, 'name': 'Phone', 'barcode': '893212299897', 'price': 500},
## {'id': 2, 'name': 'Laptop', 'barcode': '123985473165', 'price': 900},
## {'id': 3, 'name': 'Keyboard', 'barcode': '231985128446', 'price': 150}
## ]
return render_template('market.html', items=items)