CharliePrm88
CharliePrm88

Reputation: 73

Flask - Return an url from a python function to html templates

I've a function that prepare an url:

def my_url():
    params = {"client_id": CLIENT_ID,
             "response_type": "code",
             "state": "abcdefg",
             "redirect_uri": REDIRECT_URI}
url = "https://ssl.myapi.com/?" + urllib.parse.urlencode(params)
return url

How can I insert the generated link, in my templates? Eg:

< a href=my_url> login < /a>

Upvotes: 1

Views: 913

Answers (1)

Nick Dima
Nick Dima

Reputation: 348

The render_template function accepts arbitrary variables.

Simply:

render_template(‘index.html’, myurl=myurl)

And you can now access myurl from your template.

<a href=“{{myurl}}”> login </a>

Upvotes: 5

Related Questions