Home | Trees | Index | Help |
|
---|
Module servlet :: Class HTMLPage |
|
Servlet
--+
|
HTMLPage
HTMLPage
is the servlet that most developers wanting to
generate HTML will want to subclass. The respond
method of HTMLPage
calls write_html
which writes to the client a
well-defined HTML document.
Many methods and instance variables offer features to the developer to
allow the customization of their content. Use of subclassing can produce
site-wide continuity of content; e.g., you can create a servlet called
SitePage
(that inherits from HTMLPage
) that
will provide your site-wide look and feel, then individual servlets can
inherit from SitePage
.
HTMLPage
writes out an HTML document, look at
write_html
and the methods it calls.
Method Summary | |
---|---|
This first calls Servlet.repsond (to see if a method should
be called; see ok_methods_to_call ) and if it returns
False, calls write_html . | |
Write BASE tag to the client in the HEAD. | |
Writes the BODY section to the client. | |
Write the content of the BODY section. | |
This method must be overridden to produce content on the page. | |
Writes CSS to the client in the HEAD. | |
Writes to the client the <!DOCTYPE...> tag. | |
This writes the HEAD section of the HTML document to the client. | |
This method calls, in order: | |
This method produces a well-formed HTML document and writes it to the client. | |
Writes javascript to the client in the HEAD. | |
Writes META tags to the client in the HEAD. | |
Writes a LINK tag to the client specifying the shortcut icon. | |
Writes the TITLE tag to the client. | |
utility method to write HEAD tags | |
utility method to write META tags | |
Inherited from Servlet | |
Base constructor for all servlets. | |
Return a simple string representing an instance: | |
Wrapper around mod_python.Cookie.add_cookie(). | |
Basic HTTP authentication method. | |
Get the count of requests for this servlet. (Class method) | |
Send a redirect to the client via a Location HTTP header. | |
Utilily method which immediately flushes all buffered output to the client. | |
Wrapper around mod_python.Cookie.get_cookies(). | |
Redirect internally. | |
Utility method to write a message to the apache error log. | |
This is the second user method called by the handler ,
after auth , prior to respond . | |
Like write , but all output is immediately
flushed to the client and no string coercion is attempted on the
arguments. | |
Get the filename of the source file for this servlet. (Class method) | |
This is the fourth user method called by the handler ,
immediately after calling respond , before _finally . | |
Utility method to write the arguments to the client. | |
Like write , but in addition appends a newline to
the output. | |
Helper method to be used in auth . | |
This user method is the last called by the handler . | |
tuple of two strings |
Helper method to be used in auth to retrieve username and password. |
Helper method to be used in auth . |
Instance Variable Summary | |
---|---|
str |
base : If set, this will specify the BASE tag in the HEAD. |
dict |
body_attrs : Attributes for BODY tag. |
str or None | content_type : Specifies the content type of the servlet, i.e.,
"text/html". |
str |
css : A string or list of strings of CSS. |
list |
css_links : A list of hrefs (strings). |
str | doctype : See write_doctype |
one of "strict", "loose", "frameset" | dtd : See write_doctype |
dict |
http_equiv : http_equiv, like meta , produces META tags in the HEAD,
but instead of the keys being the value of the name
attribute, they are the value of the http-equiv
attribute. |
str |
js : A string or list of strings of javascript. |
list |
js_src : A list of hrefs (strings). |
dict |
meta : A dict, which if non-empty will produce META tags in the HEAD. |
str |
shortcut_icon : If non empty, specifies the href to a shortcut icon and produces a
LINK tag in the HEAD: |
str or callable | title : The title of the HTML page. |
Inherited from Servlet | |
str | auth_realm : Specifies the realm for basic HTTP authentication. |
instance of mod_python.util.FieldStorage | form : User data sent with request via form or url. |
list |
form_vars : This is the same as query_vars except these variables are only
processed for POST requests. |
float | instantiated : Timestamp of when the servlet was instantiated. |
list of unbound methods | ok_methods_to_call : list of methods that can be called directly via a POST. |
list of str | path_info : req.path_info canonicalized as a list: stripping beginning and
trailing "/" and splitting it on internal "/". |
list |
query_vars : List of arguments to be searched for in form
to be set as instance variables of the servlet. |
req : The apache request object. | |
bool | reusable : Flag (default: True) indicating whether or not an instance of this
servlet can be used for multiple requests. |
instance of mod_python.Session.Session or None | session : A Session (see the mod_python documentation for
mod_python.Session.Session). |
int | session_timeout : Length of time, in seconds, until session times out. |
bool |
use_session : If true, create (or reload) session for each request. |
Instance Method Details |
---|
respond(self)This first callsServlet.repsond (to see if a method
should be called; see ok_methods_to_call ) and if it returns
False, calls write_html .
|
write_base(self)Write BASE tag to the client in the HEAD.
|
write_body(self)Writes the BODY section to the client. This method writes "<BODY...>" to the client taking
into account the write_body_parts .
|
write_body_parts(self)Write the content of the BODY section. The base implementation simply calls For complex pages that have many sections, this method will
typically be overridden, e.g., write to the client the layout of the
site look and feel and where page-specific content should appear, call
|
write_content(self)This method must be overridden to produce content on the page. |
write_css(self)Writes CSS to the client in the HEAD. |
write_doctype(self)Writes to the client the <!DOCTYPE...> tag. By default, the following is used:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> This can be controlled by setting the |
write_head(self)This writes the HEAD section of the HTML document to the client. It first writes "<HEAD"> then calls write_head_parts .
|
write_head_parts(self)This method calls, in order:See the above methods for details about what each writes to the client. All of the above methods can have the content they write to the client controlled by setting (or unsetting) instance variables. While the base method will serve most developer needs, this method is a likely candidate to be overridden. If you want to add to the HEAD you will likely want to call the superclass method and then write additional content in your method, e.g.:class MyServlet(HTMLPage): ... def write_head_parts(self): HTMLPage.write_head_parts(self) # add my own content self.writeln(...) |
write_html(self)This method produces a well-formed HTML document and writes it to the client. It first callswrite_doctype which writes the DOCTYPE.
It then writes "<HTML>". In turn it calls write_head and write_body which write the HEAD and BODY
sections, respectively. It finishes by writing
"</HTML>".
|
write_js(self)Writes javascript to the client in the HEAD. |
write_meta(self)Writes META tags to the client in the HEAD.
|
write_shortcut_icon(self)Writes a LINK tag to the client specifying the shortcut icon.
|
write_title(self)Writes the TITLE tag to the client. It checks for thetitle instance variable. If it does
not exist it uses the name of the servlet for the title. If
title is callable it will be called (with no arguments)
and its output will be used as the title.
|
__write_head_tag(self, tag, tagtype, content)utility method to write HEAD tags |
__write_meta(self, tag, mapping)utility method to write META tags |
Instance Variable Details |
---|
body_attrsAttributes for BODY tag. Default is empty dict. If non empty, the keys will become attribute names for the BODY tag and the values will be the attribute values.
|
content_typeSpecifies the content type of the servlet, i.e., "text/html". If it is not set (None) then it defaults to "text/plain". Default: None
|
cssA string or list of strings of CSS. If non empty, a <STYLE type="text/css">...</STYLE> section will be placed in the HEAD. If css is a list of strings, the elements will be joined (seperated by newlines) and placed in a single <STYLE ...>...</STYLE> section.
|
css_linksA list of hrefs (strings). For each href, a <LINK type="text/css" rel="stylesheet" ...> will be placed in the HEAD.
|
doctypeSeewrite_doctype
|
dtdSeewrite_doctype
|
http_equivhttp_equiv, likemeta , produces META tags in the HEAD,
but instead of the keys being the value of the name
attribute, they are the value of the http-equiv attribute.
See meta for details.
|
jsA string or list of strings of javascript. If non empty, a <SCRIPT type="text/javascript">...</SCRIPT> section will be placed in the HEAD. If js is a list of strings, the elements will be joined (seperated by newlines) and placed in a single <SCRIPT ...>...</SCRIPT> section.
|
js_srcA list of hrefs (strings). For each href, a <SCRIPT type="text/javascript" src="HREF"></SCRIPT> will be placed in the HEAD.
|
metaA dict, which if non-empty will produce META tags in the HEAD. The keys of the dict will be the values of thename attribute
and their values will become the content attribute. For
example, the following value of meta:
meta = {"Author" : "Daniel Popowich", "Date" : "April 28, 2004"}will produce the following output in the HEAD: <META name="Author" content="Daniel Popowich"> <META name="Date" content="April 28, 2004">The values of the dict may be a list or tuple of strings, in which case multiple META tags will be produced for the same name
attribute. For example:
meta = {"Author" : ["Tom", "Jerry"]}will produce the following output in the HEAD: <META name="Author" content="Tom"> <META name="Author" content="Jerry">
|
shortcut_iconIf non empty, specifies the href to a shortcut icon and produces a LINK tag in the HEAD: <LINK rel="shortcut icon" href="shortcut_icon">
|
titleThe title of the HTML page. If not set, it defaults to the name of the servlet.title can be a callable that accepts no arguments,
in which case the title will be the output of the callable.
|
Home | Trees | Index | Help |
|
---|
Generated by Epydoc 2.0 on Tue Mar 15 08:20:22 2005 | http://epydoc.sf.net |