Hello, world!

1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  

View Source (/home/dpopowich/public_html/mpstutorial/index.mps)
Previous Next
Do not all tutorials start with:

Hello, world!

How it works: In the case of this servlet, we have a class named index in a file named index.mps (the handler automatically looks for a file named index.mps if a directory is specified). It subclasses TutorialBase (which, trust for now, is ultimately a subclass of mod_python.servlet.Servlet). There is only one method, write_content which makes a single call to writeln with this text.

This servlet also sets a single instance variable, title, which sets the title of this page.

After viewing the python source (click on the link above) you may be wondering how the big, centered title got on this page, as well as the horizontal rules and the navigation links, etc. They come from the TutorialBase superclass, but do not worry about that for now; that will be explained later in this tutorial. For now, just know that all the output made by write_content with calls to writeln will go between the horizontal rules.

If you view the HTML that is generated by the servlet you will notice that all the content sent to the browser by write_content is placed inside <BODY>...</BODY> tags. How the rest of the HTML is generated and how you can control it will be shown throughout this tutorial.

In the next example, you will see what happens when you do not override write_content.


Previous Next