Skip to content Skip to sidebar Skip to footer

Cannot Display A Line By Line List On Flask Webpage

this is the function i used to return the list line by line : def listing(table): x=0 tab=[] for item in range(0,len(table)): x+=1 result= f'{x}- {table

Solution 1:

Rather joining the list with \n, join it with <br> , <br> tag means break line.

final = '<br>'.join(tab)

Use safe filter to render it as html rather then plain text.

{{Key|safe}}

Solution 2:

As @charchit pointed out, you should use <br> (HTML line break) to join your list so that new line can be displayed in your HTML page.

Aside from that, it seems you would like to loop through a list to get both index and value. You actually can do it with enumerate() function. By combining with Python list comprehension, your listing() function can be rewritten as below:

deflisting(table):
    final = '<br>'.join([f'{i+1}- {item}'for i, item inenumerate(table)])
    print(final)
    return final

Post a Comment for "Cannot Display A Line By Line List On Flask Webpage"