{% extends "layout.html" %}
{% load gauges gauge_alias static %}
{% block title %}{{ title }}{% endblock %}
{% block body %}
<h1>{{ title }}</h1>
<img id="buoy" src="{% static 'observatory/buoy.svg' %}" alt="浮标示意图" width="58" height="38">
<section aria-label="变量与过滤器">
<p>站名 <span id="station">{{ station.name }}</span>,首项 <span id="first">{{ entries.0 }}</span></p>
<p>列表 <span id="sequence">{{ entries }}</span>,字典 <span id="mapping">{{ station }}</span></p>
<p id="case">{{ greeting|lower }} / {{ entries|first|upper }}</p>
<p id="truncated">{{ description|truncatewords:2 }} / {{ label|truncatechars:3 }}</p>
<p id="date">{{ sample_date|date:"Y-m-d" }} / {{ sample_date|date:"F j, Y" }}</p>
<p id="length">{{ label|length }} / {{ entries|length }} / {{ station|length }} / {{ deduped|length }}</p>
<p id="size">{{ nbytes|filesizeformat }}</p>
<p id="defaulting">{{ zero|default:"待测" }} / {{ zero|default_if_none:"无值" }} / {{ absent|default_if_none:"无值" }}</p>
<p id="slashes">{{ quotes|addslashes }}</p>
<p id="escape">{{ untrusted }}</p><p id="trusted">{{ badge|safe }} / {{ server_badge }}</p>
</section>
<section aria-label="模板控制流">
<p id="grade">{% if enabled and score >= 90 and score <= 100 %}复测优先{% elif enabled and score >= 60 %}正常值{% else %}暂无有效值{% endif %}</p>
<p id="flag">{% if not enabled or fresh %}{% if fresh %}新记录{% else %}已停用{% endif %}{% endif %}</p>
<ul id="entries">{% for entry in entries %}
<li data-counters="{{ forloop.counter }},{{ forloop.counter0 }},{{ forloop.revcounter }},{{ forloop.revcounter0 }},{{ forloop.first|yesno:'true,false' }},{{ forloop.last|yesno:'true,false' }}">{{ entry }}</li>
{% empty %}<li data-empty="yes">暂无序列数据</li>{% endfor %}</ul>
<ul id="reverse">{% for entry in entries reversed %}<li>{{ entry }}</li>{% endfor %}</ul>
<ul id="dict">{% for key, value in station.items %}<li>{{ key }}={{ value }}</li>{% endfor %}</ul>
<ul id="nested">{% for group in groups %}{% for sample in group.samples %}<li>{{ group.name }}={{ sample }}</li>{% endfor %}{% endfor %}</ul>
{# LOCAL-COMMENT-HIDDEN #}
</section>
<section aria-label="标签与表单">
<p id="custom">{{ 7|scale_reading:4 }} / {% sample_volume 2 3 5 %}</p>
<p id="safe-attr">{% readout untrusted station.depth %}</p>
<form method="post" action="{% url 'dashboard' %}">
{% csrf_token %}
<label>观测备注 <input name="note" required maxlength="60"></label>
<button type="submit">提交备注</button>
</form>
{% if submitted %}<p id="submitted">{{ submitted }}</p>{% endif %}
</section>
{% endblock %}
本例需在 CPython 3.12.14、Django 5.2.19、Edge 本机实测 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程
运行环境:CPython 3.12.14、Django 5.2.19、Edge 本机实测
入口文件:projects/django-template-lab/templates/observatory/dashboard.html
本地运行步骤快速上手
- 点击上方“保存源码”保存为
dashboard.html,或下载右侧课程工程包。 - 确认本地已准备 CPython 3.12.14、Django 5.2.19、Edge 本机实测。
- 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载
课程关联工程包(登记关联31章) · 含当前章节或实例 · mbskycom202612a164.zip
课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a179.zip