如何使用 Python 更新 HTML 文件中的值?

How to update a value in a HTML file using Python?

我正在从 Arduino 接收数据,使用 Python 解析它,我的目的是使用串行数据更新 HTML 中的值。像 <h6>value</h6> 这样,当我刷新页面时,新值就会出现。怎么做?

我不确定你的情况,但是,我们使用 python 作为服务器端语言并制作动态 HTML,我们使用为 Django 开发的 Django 模板 (A python 基于框架)。 这是使用一些数据制作简单 html 的示例:

<!DOCTYPE html>
<html>
 <head>
  <meta name="keywords" content="{{ meta.keywords }}" />
  <meta name="robots" content="index,follow" />
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>
  <meta name="HandheldFriendly" content="true"/>

  <title>{{ meta.title}}</title>
  <meta name="description" content="{{ meta.description }}">
  <meta name="og:description" content="{{ meta.description }}">
  <meta property="og:title" content="{{ meta.title }}" />
  <meta property="og:image" content="{{ meta.image_url}}" />
  <meta property="og:image:type" content="image/png" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" charset="utf-8">
</head>
<body>
  <h1>{{ data.title }}</h1>

  <h2>{{ data.description }}</h2>

  {% if data.additional_info %}
   <p>
    {{ data.additional_info }}
   </p>
  {% endif %}

  {% if data.list1|length > 0  %}
   {% for item in data.list1 %}
    <h2>{{ item.title }}</h2>
    <p>
     {{ item.content }}
    </p>
   {% endfor %}
  {% endif %}

 {% if data.list2|length > 0  %}
   {% for item in data.list2 %}
    <h2>{{ item.title }}</h2>
    <p>
      {{ item.content }}
    </p>
  {% endfor %}
{% endif %}

{% if data.list3|length > 0  %}
  {% for item in data.list3 %}
    <h2>{{ item.title }}</h2>
    <p>
       {{ item.content }}
    </p>
   {% endfor %}
 {% endif %}

 </body>
</html>