```
--------------------------------
### Generate HTML Page with Brython Support (Python)
Source: https://context7_llms
This Python code demonstrates the creation of a basic HTML page using the html_codegen library. It showcases the use of context managers for structuring the document and method calls for adding content. The generated HTML is saved to a file named 'page.html'.
```python
from html_codegen import html, head, body, title, div, p, h1
with html() as doc:
with head():
title("Моя первая страница")
with body():
h1().text("Добро пожаловать!")
div().p().text("Это мой первый пример с HTML Codegen.")
doc.save("page.html")
```
--------------------------------
### Create Semantic HTML5 Page Structure in Python
Source: https://context7_llms
Shows how to build a semantically structured HTML page using HTML5 elements like header, main, article, and footer. This approach improves SEO and accessibility. The generated HTML is saved to 'semantic.html'.
```python
from html_codegen import html, head, body, title, header, main, article, footer, h1, h2, p
with html() as doc:
with head():
title("Семантическая страница")
with body():
with header():
h1().text("Заголовок сайта")
with main():
with article():
h2().text("Статья")
p().text("Содержание статьи")
with footer():
p().text("Подвал сайта")
doc.save("semantic.html")
```
--------------------------------
### Generate HTML Table and Save
Source: https://context7_llms
Creates an HTML table representing sales data for a quarter, including headers, body rows, and a footer summary. The generated HTML is saved to 'sales.html'. This demonstrates table structure generation.
```python
from html_codegen import (
html, head, body, title, table, thead, tbody, tfoot,
tr, th, td, caption, h1, div
)
with html() as doc:
with head():
title("Отчет по продажам")
with body():
h1().text("Продажи по месяцам")
with table(attrs={"border": "1"}):
caption().text("Продажи за квартал")
with thead():
with tr():
th().text("Месяц")
th().text("Продажи")
th().text("Прибыль")
with tbody():
with tr():
td().text("Январь")
td().text("100,000")
td().text("20,000")
with tr():
td().text("Февраль")
td().text("120,000")
td().text("25,000")
with tr():
td().text("Март")
td().text("110,000")
td().text("22,000")
with tfoot():
with tr():
th().text("Итого")
th().text("330,000")
th().text("67,000")
doc.save("sales.html")
```
--------------------------------
### Generate Brython Interactive App HTML
Source: https://context7_llms
Generates an HTML file for a Brython-enabled interactive application. It includes a title, heading, a div with a button and paragraphs, and integrates Python code to run in the browser. The output is saved to 'brython_app.html'.
```python
from html_codegen import html, head, body, title, div, button, p, h1, pyscript
with html(use_brython=True) as doc:
with head():
title("Brython приложение")
with body():
h1().text("Интерактивное приложение")
with div(attrs={"id": "app"}):
p().text("Нажмите кнопку")
button(attrs={"id": "btn"}).text("Кликни меня")
p(attrs={"id": "result"})
# Python код выполнится в браузере
pyscript("web.scripts.py.app")
doc.save("brython_app.html")
```
--------------------------------
### Generate Basic HTML Page with HTML Codegen (Python)
Source: https://context7_llms
This snippet demonstrates how to generate a simple HTML page using the html_codegen library. It utilizes context managers for hierarchical structure and method calls for creating elements and setting text content. The generated HTML is saved to a file.
```python
from html_codegen import html, head, body, title, div, p, h1
with html() as doc:
with head():
title("Моя страница")
with body():
h1().text("Привет, мир!")
with div(attrs={"class": "container"}):
p().text("Это пример использования html_codegen.")
doc.save("index.html")
```
--------------------------------
### Create HTML Lists (Ordered and Unordered) in Python
Source: https://context7_llms
Demonstrates the creation of both ordered (numbered) and unordered (bulleted) lists in HTML using the html_codegen library. Each list item is defined using the 'li' tag. The generated HTML is saved to 'lists.html'.
```python
from html_codegen import html, body, ul, ol, li, h2
with html() as doc:
with body():
h2().text("Нумерованный список:")
with ol():
li().text("Первый элемент")
li().text("Второй элемент")
li().text("Третий элемент")
h2().text("Маркированный список:")
with ul():
li().text("Элемент 1")
li().text("Элемент 2")
li().text("Элемент 3")
doc.save("lists.html")
```
--------------------------------
### Generate HTML with Attributes in Python
Source: https://context7_llms
Demonstrates how to create HTML elements with specific attributes using the html_codegen library. The 'p' tag is used with a 'class' attribute to style the text. The resulting HTML is saved to 'attrs.html'.
```python
from html_codegen import html, p
with html() as doc:
p(attrs={"class": "highlight"}).text("Текст с атрибутами")
doc.save("attrs.html")
```
--------------------------------
### Generate HTML Form and Save
Source: https://context7_llms
Generates a simple HTML form with password input and a submit button, then saves it to a file named 'register.html'. This snippet showcases basic HTML element creation.
```python
from html_codegen import html, input, button
with html() as doc:
input(attrs={"type": "password", "id": "password", "name": "password"})
button(attrs={"type": "submit"}).text("Зарегистрироваться")
doc.save("register.html")
```
--------------------------------
### Dynamically Generate HTML Navigation Menu
Source: https://context7_llms
Implements a Python function `create_navigation_menu` that generates an HTML navigation list (`