Typerror() in python while passing parameters to the route [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Typerror() in python while passing parameters to the route [duplicate]



This question already has an answer here:



I need to pass parameter to routes using url_for() function and redirect() I think I did the same. But, I get TypeError: book() missing 1 required positional argument: 'book_title' I know that the parameter book_title is not being recieved by the book() function in my code and thats why the error. But, I dont know what's going wrong behind the scenes.
These are my routes


url_for()


redirect()


TypeError: book() missing 1 required positional argument: 'book_title'


book_title


book()


@app.route('/search/<title>/',methods=['GET','POST'])
def btitle(title):
book_title = db.execute("SELECT title,author,isbn from books WHERE (title LIKE :title)",params={"title":title}).fetchall()
if request.method == 'GET':
#book_title = db.execute("SELECT title,author,isbn from books WHERE (title LIKE :title)",params={"title":title}).fetchall()
if book_title:
return render_template("booktitle.html",book_title=book_title)
else:
return render_template("error.html")
else:
#book_title = db.execute("SELECT title,author,isbn from books WHERE (title LIKE :title)",params={"title":title}).fetchall()
if book_title:
return redirect(url_for("book",book_title=book_title))

@app.route('/books',methods=['GET','POST'])
def book(book_title):
if request.method == 'GET':
return render_template("individualbook.html",book_title=book_title)



This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.




1 Answer
1



You problem is that the book route is not getting the argument book_title that it expects.


book


book_title



This is because you are defining it like this:


@app.route('/books',methods=['GET','POST'])
def book(book_title)



In flask, if you want your view functions to take parameters you need to include them in the route. In your example this could look like this:


@app.route('/books/<book_title>',methods=['GET','POST'])
def book(book_title)



If you do not put the <book_title in the route, flask will not be able to provide the book_title parameter to the book function which is what it tells you in the error.


<book_title


book_title


book

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

'Series' object is not callable Error / Statsmodels illegal variable name