我正在尝试在烧瓶中构建一个图书馆管理系统,我想在其中根据图书的用户名和序列号发行/归还图书。
我正面临一个属性错误。请帮我解决它。
这是回溯错误:
Traceback (most recent call last):
File "C:\Users\MADHURA\PycharmProjects\program2\venv\lib\site-packages\flask\app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\MADHURA\PycharmProjects\program2\venv\lib\site-packages\flask\app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\MADHURA\PycharmProjects\program2\venv\lib\site-packages\flask\app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\MADHURA\PycharmProjects\program2\venv\lib\site-packages\flask\_compat.py", line 35, in reraise
raise value
File "C:\Users\MADHURA\PycharmProjects\program2\venv\lib\site-packages\flask\app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\MADHURA\PycharmProjects\program2\venv\lib\site-packages\flask\app.py", line 1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "C:/Users/MADHURA/Desktop/Library-Managment-System-master/library.py", line 289, in book_issue_return
book.quantity=book.quantity-1
AttributeError: 'bool' object has no attribute 'quantity'
我正在使用的功能:
def book_issue_return():
if check_admin():
if request.method == 'POST':
if not request.form['username'] or not request.form['serialno']:
flash('Please Fill All The Fields')
elif not User_Login.query.filter(User_Login.username==request.form['username']).first():
flash("Username is Wrong")
if request.form['Submit']=='Issue':
if Book.query.filter(Book.serialno==int(request.form['serialno'])).first().quantity==0:
flash('The Book Is Not Available')
else:
user=User_Login.query.filter(User_Login.username==request.form['username']).first()
book=get_bookby_serialno(int(request.form['serialno']))
book.quantity=book.quantity-1
book.issued_on=datetime.datetime.today()
date=book.issued_on + datetime.timedelta(days=7,weeks=0,hours=0,minutes=0,milliseconds=0,microseconds=0,seconds=0)
book.to_be_returned= date
book.serialno.remove(int(request.form['serialno']))
book.save()
user.books.append(int(request.form['serialno']))
user.save()
flash('Book Successfully Issued')
return redirect(url_for('admin'))
else:
if not get_bookby_serialno(int(request.form['serialno'])):
flash("Serial No. Not In Database")
elif not int(request.form['serialno']) in User_Login.query.filter(User_Login.username==request.form['username']).first().books:
flash("The User never issued this Book")
else:
user=User_Login.query.filter(User_Login.username==request.form['username']).first()
user.books.remove(int(request.form['serialno']))
user.save()
book=get_bookby_serialno(int(request.form['serialno']))
book.quantity=book.quantity+1
book.serialno.append(int(request.form['serialno']))
book.save()
flash('Book Successfully Returned')
return redirect(url_for('admin'))
return render_template('issue-book.html')
return redirect(url_for('admin'))