Below is my models.py
from . import db
class Product(db.Model):
__tablename__='Products'
id=db.Column(db.Integer,primary_key=True)
brandname=db.Column(db.String(64),unique=True)
description=db.Column(db.String(500),nullable=False)
price=db.Column(db.Float,nullable=False)
image=db.Column(db.String(64),nullable=False,default='defaultproduct.jpg')
def __repr__(self):
str = "Id: {}, brandname: {}, description: {}, price: {}, image: {} \n"
str = str.format(self.id,self.brandname,self.description,self.price,self.image)
return str
below is my views.py
from flask import Blueprint, render_template, url_for , request , session
from .models import Product
bp = Blueprint('main',__name__)
@bp.route('/')
def index():
products= Product.query.order_by(Product.brandname).all()
return render_template('Home.html',products=products)
when I try to run the project I get error like "AttributeError: 'function' object has no attribute 'query'"
Can anyone helpme to resolve this issue ?