I'm trying to pass a number through URL and retrieve it on another page. If I try to specify the variable type, i get a malformed URL error and it won't compile. If I don't specify the var type, it will run, but the variable becomes Type None. I can't cast it to an int either. How can I pass it as an Integer...? Thanks in advance.
This gives me a malformed URL error:
@app.route('/iLike/<int: num>', methods=['GET','POST'])
location = session.get('location')
transType = session.get('transType')
data = session.get('data')
**num = request.args.get('num')**
You are mixing route parameters and request arguments here.
Parameters you specify in the route are route parameters and are a way to declare variable routes. The values for these parameters are passed as function arguments to the route function. So in your case, for your
<num> url part, the value is passed as the function argument
Request arguments are independent of routes and are passed to URLs as GET parameters. You can access them through the request object. This is what you are doing with
A full example would look like this:
@app.route('/iLike/<int:num>') def single2(num): print(num, request.args.get('num'))
/iLike/123 would now result in
123 None. The request argument is empty because you didn’t specify one. You can do that by opening
/iLike/123?num=456, which would result in