-1

I need help creating a function that returns a value within the URL string and passed back as an integer that I can used in another function.

from flask import Flask
app = Flask(__name__)
Col1= 0
Col2 = 1
Col3 = 2
array = [
        [1,2,3,4],
        [5,6,7,8],
        [9,10,11,12]
        ]


@app.route ('/<arraynum>')
def findrow(array, custid): 
 for i, x in enumerate(array):
      if id in x:
      row = i
      return row

I'm not sure how to grab the value at the end of the url that I defined as id.

My end goal is to make this code work array[findrow(array, id)][Col1] so that webpage '..../6' will output '6'

Richard
  • 11
  • 1
  • 4
  • btw, there is a Python builtin called [`id`](http://stackoverflow.com/questions/77552/id-is-a-bad-variable-name-in-python), which you are probably masking. – tiwo Apr 30 '17 at 21:17
  • I did notice that. However, our class example has a basic loop function using id as well and it seemed to work fine. I changed id to custid but now its telling me custid is not defined. I'm still not sure how to target the inputted str at the end of the link and have it be returned as a value. – Richard Apr 30 '17 at 22:43

1 Answers1

1

I think this is what you're looking for:

@app.route ('/<int:array_num>')
def print_num(array_num): 
    return render_template('myTemplate.html', num=array_num')

Then your HTML template will be set up to use the num variable somewhere using jinja, and it will be fed the variable from the address.

coralvanda
  • 6,431
  • 2
  • 15
  • 25