Kleber Vianna
Kleber Vianna

Reputation: 1

Flask @route decorator with variables

Why the fragment of code below produces error in the line commented with “this produces error”? What should I do to correct it?

@app.route('/', methods=['GET', 'POST']) 
@app.route('/index', methods=['GET']) 
@app.route('/lti/', methods=['GET', 'POST']) 
@app.route('/<fase>', methods=['GET', 'POST']) #this produces error!
@lti(request='initial', error=error, app=app) 
def index(lti=lti): 
    """ initial access page to the lti provider.  This page provides 
     authorization for the user. 

    :param lti: the `lti` object from `pylti` 
    :return: index page for lti provider 
    """ 
    return render_template('index.html', lti=lti)

Upvotes: 0

Views: 831

Answers (1)

davidism
davidism

Reputation: 127190

<fase> is a variable placeholder. It captures a string at that position in the url and passes that to the view function. It is passed as a keyword with the same name as the placeholder, so the view function needs to accept an argument with the same name (or **kwargs).

@app.route('/<fase>', methods=['GET', 'POST'])
def index(fase=None, lti=lti):
    pass

Upvotes: 2

Related Questions