-3

I'm trying to build a web application that takes in as arguments, the youtube watch ID or something, for example: 'watch?v=[something random here]'. Whenever I try to get this as a variable using the < > signs, in the @app.route decorator, the value that the variable stores, stops at the '?' (exclusive). Is there some way I can get this right? I want to take the whole 'watch?v=[random]' in my variable.

Siddnikh
  • 3
  • 1

2 Answers2

0

I am not sure what you exactly are referring to, adding some code would be helpful. But when it comes to getting the query string you want to look into the request object in flask that can return information about the URL. Hope this helps and add some code if possible.

Shrey
  • 146
  • 2
  • 11
0

You are kind of confused as to what you are asking. Anyway there are two ways about it. If you are willing to accept dynamic values from the route, you can use request from flask. Here is an example:

Solution 1

from flask import request
@app.route("/watch")
def home():
    page = request.args.get('v')
    # use the 'v' in what you want to do
    return # what you want

Solution 2 Otherwise, this is what you can do:

from package.file import Something
@app.route("/post/<int:post_id>")
def post(post_id):
    post = Something.query.get_or_404(post_id)
    return render_template('post.html', title=post.title, post=post)

The above part has a particular input defined. The dynamic part of the route does not start with the '?'

Guessing by your confusion, the first solution should work for you!

yasnil
  • 77
  • 8