Display Data from Python to HTML

0
7K

When making a web application, you're probably thinking if displaying data from Python to HTML is possible. The good news is that it is possible! The only library required for Python is called Jinja2. With Jinja2, you can render HTML files and place key values in the file. Here's an example:

templates/index.html:
<div class="container" id="container" style="text-align: center;color: white;">    {% if get_count %}
        <input type="checkbox" id="toggle-button" class="toggle-button" checked>
    {% else %}
        <input type="checkbox" id="toggle-button" class="toggle-button">
    {% endif %}

</div>

main.py:

@app.route('/')

async def main_page(request):

    return await render('moderation.html', context={'get_count': ...})

Search
Categories
Read More
Arts, Culture and Entertainment
Sunset Blvd. (1950)
A screenwriter develops a dangerous relationship with a faded film star determined to make a...
By Leonard Pokrovski 2022-12-16 15:53:32 0 17K
Sport
Sisters on Track (2021)
A coming of age story about hope, belonging, and the metaphorical and literal sisterhood of young...
By Leonard Pokrovski 2022-09-02 18:21:53 0 22K
Financial Services
Explicit and implicit costs and accounting and economic profit
Key points Privately owned firms are motivated to earn profits. Profit is the...
By Mark Lorenzo 2023-02-23 18:34:44 0 9K
Financial Services
Beyond GDP: other ways to measure the economy
Key points Gross national product, or GNP, includes what is produced...
By Mark Lorenzo 2023-03-03 19:43:30 0 12K
Financial Services
Command-and-control regulation
Key points Command-and-control regulation sets specific limits for pollution...
By Mark Lorenzo 2023-05-01 20:28:31 0 9K
image/svg+xml


BigMoney.VIP Powered by Hosting Pokrov