1

Trying to get the html document be able to take in variables from my flask app, but this part is inside a string. How do I go about this?

I tried this:

<iframe 
src="https://embed.spotify.com/?uri=spotify%3Auser%3A{{playerid}}%3Aplaylist%3A{{playlistid}}&theme=white".format() width="1400" height="800" frameborder="0" allowtransparency="true"> 
</iframe>

but doesn't seem to work. The {{playlistid}} and {{playerid}} is from the python flask app,

return render_template(
    "player.html", playerid = LogInfo['username'], 
    playlistid=LogInfo['playlist'])
ranakrunal9
  • 13,320
  • 3
  • 42
  • 43
James B Lee
  • 59
  • 1
  • 4

2 Answers2

0

Just pass the variable name:

src="https://embed.spotify.com/?uri=spotify%3Auser%3A{{ playerid }}%3Aplaylist%3A{{ playlistid }}&theme=white">
metmirr
  • 4,234
  • 2
  • 21
  • 34
0

It is no problem to place Jinja2 expressions or variables inside Strings. In fact this is done very often. Jinja2 is rendered by Python on the server side before the HTML code is interpreted so it doesn't matter where in your HTML document your Jinja2 statement is located.

There is actually nothing wrong with your code except of the format() function at the end of your string. No need for that. Have a look at the Jinja2 documentation for further infos.

MrLeeh
  • 5,321
  • 6
  • 33
  • 51