Light html generator
pip3 install htmlightDespite htmlight is able to generate full html page, it is designed to generate small fragments of code like:
fromhtmlightimporthfromflask_babelimportlazy_gettextfromflask_loginimportcurrent_userTEMPLATE=h.div(h.hr(), h.span("{hello} {username}"), h.hr())
defget_html():
returnTEMPLATE.format(hello=lazy_gettext("Hello"), username=current_user.name)fromhtmlightimporthfromflask_babelimportlazy_gettextfromflask_loginimportcurrent_userdefget_html():
returnh.div(h.hr(), h.span(lazy_gettext("Hello"), " ", current_user.name), h.hr()))fromhtmlightimporthlanding_page=h.html(
h.head(
h.title("Welcome to Our Website"),
h.link(rel="stylesheet", href="styles.css"),
),
h.body(
h.header(
h.h1(
"Welcome to Our Website",
style=(
" color:"" #333;"" text-align:"" center;"" background-color:"" #F0F0F0;"" padding: 20px;"
),
),
h.p(
"Explore our amazing content",
style="font-size: 20px; color: #555;",
),
),
h.main(
h.h2("Featured Articles", style="color: #444; text-align: center;"),
h.article(
h.h3("Article 1", style="color: #0072d6;"),
h.p("This is the first article content", style="color: #666;"),
),
h.article(
h.h3("Article 2", style="color: #00a86b;"),
h.p("This is the second article content", style="color: #666;"),
),
),
h.footer(
h.p(
"© 2023 Our Website",
style=(
"text-align: center;"" background-color: #333;"" color: #fff;"" padding: 10px;"" flex-shrink: 0;"" background-color: #333;"" position: absolute;"" left: 0;"" bottom: 0;"" width: 100%;"" overflow: hidden;"
),
),
),
),
style="background-color: #f2f2f2; font-family: Arial, sans-serif;",
)
withopen("landing_page.html", "w") asf:
f.write(landing_page)