如何解决,“ AttributeError:'bool'对象没有属性'quantity'” flask应用程序中出现错误

时间:2019-05-13 06:06:13

标签: python-3.x flask attributeerror mongoalchemy

我正在尝试在flask中建立一个图书馆管理系统,在该系统中我想根据该书的用户名和序列号发行/归还该书。

我面临属性错误。请帮助我解决问题。

这是回溯错误:

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'))

0 个答案:

没有答案