Flask - sending data through with GET request

810 views Asked by At

I am building simple Flask web-app using Google books API. I am a beginner and maybe overthinking details, but something tells me I haven't designed this very well.

Problem I am facing:

  • Find book through search bar
  • Button on each search result to post review page: review/book/<book_id> - POST request
  • Actual page where you write review and submit: summary/add/<book_id> - POST request

What I find strange is that I have POST request following another POST request, just because I couldn't find a way how to send <book_id> over to the write review page. There is also problem redirecting user back since this page is @login_required but there is no GET request on it.

So my main question is: Is there a way to send <book_id> over without making the initial post request (from search result to post review page)? Maybe with javascript?

Thank you

1

There are 1 answers

1
Simplecode On

If I understood correctly, you have to send <book_id> in a GET request ?

If yes, you can do something on following lines

@api_blueprint.route('/books/<int:book_id>', methods=['GET'])  #you can use the decorator yor have 
def get_by_id(book_id):
    print(book_id)

I had defined the blueprints for my application. But it's okay even if you don't have that. You can use simply @app.route, or the one which you have for other POST apis.

from flask import Flask

app = Flask(__name__)


@app.route('/')
def hello():
    return 'Hello, World!'