-1

so I have

@app.route("/Current.html")
def current():

  recent = api_info.user(user_name="GDcheerios")

  return render_template(
    'Current.html',  # Template file
    recent = recent
  )

just as a basic test code.

here is the html file where the variable recent is

<body style="background: linear-gradient(0deg, #143827, #266849);">

  <a style="color: black; text-align: center;" href="\">Go back...</a>
  <div class="match">
    <h1>TEST</h1>
    <h1>TEST</h1>
    <h1>TEST</h1>
    <h1>TEST</h1>
    <h1>TEST</h1>
    <h1>TEST</h1>
    <h1>TEST</h1>
    <h2>{{ recent.events }}</h2>
  </div>

</body>

it outputs with

TEST TEST TEST TEST TEST TEST TEST

[{'display_html': "<img src='/images/A_small.png'/> <b><a href='/u/11339405'>GDcheerios</a></b> achieved rank #985 on <a href='/b/192258?m=0'>Itou Kanae - Puzzle (TV Size) [Hard]</a> (osu!)", 'beatmap_id': 192258, 'beatmapset_id': '63851', 'date': datetime.datetime(2021, 3, 1, 1, 37, 23, 260000), 'library': '', 'epic_factor': '1'}]

I would like to have this html put into the html file automatically with each variable that I call.

GDcheerios
  • 21
  • 4
  • So you want `display_html` only in this case. It looks like `recents.events` is a `list(dict)`. Are there more than one element to this list? – astrochun Mar 26 '21 at 14:09
  • GDcheerios achieved rank #985 on Itou Kanae - Puzzle (TV Size) [Hard] (osu!)" so it has extra data after the html, and yeah there is more than one element, these are all the elements "display_html":"htmlcode", 'beatmap_id': 192258, 'beatmapset_id': '63851', 'date': datetime.datetime(2021, 3, 1, 1, 37, 23, 260000), 'library': '', 'epic_factor': '1' – GDcheerios Mar 26 '21 at 14:42
  • I can provide an answer later as I would need to test, but you should be able to access that list element and that dictionary much like python syntax. Something like `{{ recent.events[0]['display_html'] | safe }}`. The safe should preserve the HTML syntax and render it as such. – astrochun Mar 26 '21 at 16:37

1 Answers1

0

If you want to inject html into already generated HTML, you can replace the element.innerHTML on the JS side.

G.Vernier
  • 369
  • 2
  • 14
  • well I am not sure if I am getting what your saying but what I tried was using regex to get only the html part out of recent events and keep that as a separate variable, then in html set a js variable for the script.

    {{ recent.events }} | {{ html_finder }}

    – GDcheerios Mar 26 '21 at 16:10