liveBook · Manning

HTML template

As explained in Build Your Own Robot: Using Python, CRICKIT, and Raspberry Pi

An HTML template is an HTML document containing markup and placeholders intended to be rendered by a web application.

An HTML template is a page stored in a templates directory and rendered by a web request handler. It combines ordinary markup with placeholders such as {{ stamp }} and controls that submit actions to the application. section 6.3.3 section 6.4.1

A robot-control template can:

  • Display a timestamp supplied by the handler. section 6.3.3
  • Submit movement commands with POST forms and button actions. section 6.3.3
  • Group forward, backward, turning, spinning, and no-operation controls into a touch-friendly layout. section 6.4.1
  • Use HTML5-named character references and CSS to provide graphical buttons with consistent sizing and spacing. section 6.4.1

Robot movement template

A compact template places two POST forms on the page: one submits to forward and the other to backward. The handler renders forward.html, dispatches the requested motor function, and redirects to the home page after the action. section 6.3.3

Listing 6.6 full.html: HTML user interface that supports all robot movement actions
<!DOCTYPE HTML>
<html lang="en">
<head>
  <title>Robot Web</title>
  <meta name="viewport" content="width=device-width">
  <link rel="icon" href="data:,">
<style>
body, a {
  font-family: Verdana, Arial, sans-serif;
  text-align: center;
  text-decoration: none;
}
button {
  font-size: 300%;
  margin: 0px 10px;
  height: 60px;
  width: 60px;
}
</style>
</head>
<body>
<h1><a href='/'>Robot Web</a></h1>
{{ stamp }}<br><br>
<form method="post">
  <button formaction="forward">&blacktriangle;</button>
  <button formaction="backward">&blacktriangledown;</button>
  <br><br>
  <button formaction="left">&blacktriangleleft;</button>
  <button formaction="right">&blacktriangleright;</button>
  <br><br>
  <button formaction="spin_left">&circlearrowleft;</button>
  <button formaction="spin_right">&circlearrowright;</button>
  <br><br>
  <button formaction="noop">X</button>
</form>
</body>
</html>

Inspect the complete full.html interface, including the timestamp placeholder, movement buttons, HTML5 symbols, and responsive styling. section 6.4.1

How Build Your Own Robot: Using Python, CRICKIT, and Raspberry Pi covers it

How deep it goes
Explains file placement, rendering, forms, placeholders, styling, and request flow, but does not descend into template-engine internals.
Examples
Uses forward.html and full.html to demonstrate two movement buttons and a complete touch-oriented movement panel.
What it assumes
Assumes a working motor module and web application structure, while demonstrating template files, forms, and styling incrementally.
What you can do after
Builds a Tornado-powered HTML control page that renders values and triggers named robot movement functions.
How it connects
Connects HTML templates with web applications, HTTP POST forms, request handlers, redirects, and motor control.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Your Own Robot: Using Python, CRICKIT, and Raspberry Pi. The section links point to the parts of the book it draws on.