anvd
anvd

Reputation: 4047

Parse url with jinja

In jinja, I can do {{request.path}} to get the url. However, i have a token, that is dynamic, so i can't check the entire url.

/users/review/step2/c/DqBJjAZ4PdmpfhzbXBc5g9
/users/review/step2/u/DqBJjAZ4PdmpfhzbXBc5g9

My question is about identify the part with /c/ or /u/. c is create and u update.

After that i can build an url_for using c or u accordingly the url. What is the best way to identify if the url is to create or update?

Upvotes: 1

Views: 1640

Answers (1)

AlexLordThorsen
AlexLordThorsen

Reputation: 8488

I would suggest just passing a variable to your template to be used in the template.

so

@app.route('/users/review/step2/c/<token>')
def if_template(token):
    return render_template(
        "template.jinja2",
        create=True)

@app.route('/users/review/step2/u/<token>')
def if_template(token):
    return render_template(
        "template.jinja2",
        update=True)

if you're only two states are create and update than one variable will probably suffice.

Upvotes: 2

Related Questions