Flask URL variable type None?
<p>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.</p>

<p>This gives me a malformed URL error:</p>

<pre><code>@app.route('/iLike/&lt;int: num&gt;', methods=['GET','POST'])
def single2(num):
</code></pre>

<p>This runs but gives me a var of type none that I can't work with:</p>

<pre><code>@app.route('/iLike/&lt;num&gt;', methods=['GET','POST'])
def single2(num):
     try:
        location = session.get('location')
        transType = session.get('transType')
        data = session.get('data')

        **num = request.args.get('num')**
</code></pre>

<p>You are mixing route parameters and request arguments here.</p>

<p>Parameters you specify in the route are route parameters and are a way to declare <a href="http://flask.pocoo.org/docs/0.11/quickstart/#variable-rules" rel="nofollow">variable routes</a>. The values for these parameters are passed as function arguments to the route function. So in your case, for your <code>&lt;num&gt;</code> url part, the value is passed as the function argument <code>num</code>.</p>

<p>Request arguments are independent of routes and are passed to URLs as GET parameters. You can access them through the <a href="http://flask.pocoo.org/docs/0.11/quickstart/#the-request-object" rel="nofollow">request object</a>. This is what you are doing with <code>request.args.get()</code>.</p>

<p>A full example would look like this:</p>

<pre><code>@app.route('/iLike/&lt;int:num&gt;')
def single2(num):
    print(num, request.args.get('num'))
</code></pre>

<p>Opening <code>/iLike/123</code> would now result in <code>123 None</code>. The request argument is empty because you didnât specify one. You can do that by opening <code>/iLike/123?num=456</code>, which would result in <code>123 456</code>.</p>

python flask