[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版

(yzsuai) #1

Figure 15-2. A simple web page from an HTML file


To truly understand how this little file does its work, you need to know something
about HTML syntax, Internet addresses, and file permission rules. Let’s take a quick
first look at each of these topics before we move on to the next example.


HTML basics


I promised that I wouldn’t teach much HTML in this book, but you need to know
enough to make sense of examples. In short, HTML is a descriptive markup language,
based on tags— items enclosed in <> pairs. Some tags stand alone (e.g.,


specifies
a horizontal rule). Others appear in begin/end pairs in which the end tag includes an
extra slash.


For instance, to specify the text of a level-one header line, we write HTML code of the
form

text

; the text between the tags shows up on the web page. Some tags
also allow us to specify options (sometimes called attributes). For example, a tag pair
like text specifies a hyperlink: pressing the link’s text in the
page directs the browser to access the Internet address (URL) listed in the href option.


It’s important to keep in mind that HTML is used only to describe pages: your web
browser reads it and translates its description to a web page with headers, paragraphs,
links, and the like. Notably absent are both layout information—the browser is re-
sponsible for arranging components on the page—and syntax for programming logic—
there are no if statements, loops, and so on. Also, Python code is nowhere to be found
in Example 15-2; raw HTML is strictly for defining pages, not for coding programs or
specifying all user interface details.


HTML’s lack of user interface control and programmability is both a strength and a
weakness. It’s well suited to describing pages and simple user interfaces at a high level.
The browser, not you, handles physically laying out the page on your screen. On the
other hand, HTML by itself does not directly support full-blown GUIs and requires us
to introduce CGI scripts (or other technologies such as RIAs) to websites in order to
add dynamic programmability to otherwise static HTML.


1136 | Chapter 15: Server-Side Scripting

Free download pdf