I create the database and try to connect the market page. But I got this error here.
Traceback (most recent call last): File "C:\Users\David\AppData\Local\Programs\Python\Python38\Lib\site-packages\sqlalchemy\util_collections.py", line 1008, in call return self.registry[key] KeyError: <greenlet.greenlet object at 0x0000026A2C0F5300 (otid=0x0000026A2C10AE80) current active started main>
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:\Users\David\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 2088, in call return self.wsgi_app(environ, start_response) File "C:\Users\David\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask_sqlalchemy_init_.py", line 914, in apply_driver_hacks sa_url.database = os.path.join(app.root_path, sa_url.database)
AttributeError: can't set attribute
My code is here.
from flask import Flask, render_template
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///market.db'
db = SQLAlchemy(app)
class Item(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(30), nullable=False, unique=True)
price = db.Column(db.Integer, nullable=False)
barcode = db.Column(db.String(12), nullable=False, unique=True)
description = db.Column(db.String(1024), 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()
return render_template('market.html', items=items)
if __name__ == "__main__":
app.run(debug=True)
My requirements.txt is here
click==8.0.2
colorama==0.4.4
Flask==1.1.2
Flask-SQLAlchemy==2.5.0
greenlet==1.1.2
install==1.3.4
itsdangerous==2.0.1
Jinja2==3.0.2
MarkupSafe==2.0.1
SQLAlchemy==1.3.23
Werkzeug==2.0.2
I really want to know what happend is going on.