不允许的方法:请求的方法不允许 URL

Method Not Allowed : The method is not allowed for the requested URL

@app.route('/<int:bookid>')

def view(bookid):

    if "user" in session:
        user = session["user"]


        review = ReviewForm(request.form)

**# ...get isbn,author,username,title from database**

      if request.method == 'POST':
            review = review.data['review']
            stars = review.data['stars']
            db.execute("INSERT INTO reviews (username,review,bookid,stars)  VALUES (:u,:r,:bi,:s)",{"u":user,"r":review,"bi":bookid,"s":stars})
            db.commit()

        rev=db.execute("SELECT EXISTS(SELECT REVIEW FROM reviews WHERE reviews.bookid = :id AND reviews.username =:username )",{"id":bookid,"username":user}).fetchone()[0]

**# ...get rating from api**

        results=[]

        res=db.execute("SELECT * from reviews WHERE bookid = :id",{"id":bookid})
        results=res.fetchall()

        if len(results) != 0:
               table = Reviews(results)
               table.border = True
               return render_template("bookdetails.html",rev=rev,user=user,title=booktitle,bookisbn=bookisbn,author=bookauthor,year=bookyear,table=table,form=review)

        else:
               return render_template("bookdetails.html",rev=rev,user=user,title=booktitle,bookisbn=bookisbn,author=bookauthor,year=bookyear,table="No Reviews",form=review)


    else:
        return redirect(url_for('login'))

方法不允许:所请求的方法不允许URL发布评论时出现错误

您的 @app.route('/') 需要包含 methods 参数和 POST 作为选项。默认情况下,这不包括在内,只允许 GET:

@app.route('/', methods=['GET', 'POST'])