Starting in Xierpa

A simple page

Xierpa run Python scripts as page application. A simple example of such page can be seen below:
# -*- coding: UTF-8 -*-
from xpyth.xierpa.builders.xierpabuilder import XierpaBuilder

class Home(XierpaBuilder):
			
	def build(self):
		self.doctype('xhtml-transitional')
		self.html()
		self.head()
		self.title()
		self.text('Title of "Hello world" page')
		self._title()
		self._head()
		
		self.body()	
		self.text('Hello world')
		self._body()
		self._html()

Home(e, result).build()
Example 1

This simple page shows in the browser as follows:


(click on the image to see the page in the browser)

What the Xierpa code lines do

# -*- coding: UTF-8 -*-
Make all Python document of type "UTF-8", so they will easily show unicode.
from xpyth.xierpa.builders.xierpabuilder import XierpaBuilder
Import one of the builders. Normally you want the XierpaBuilder. It includes all of the nice building block to create pages (see an overview of all available tags here). It also extends from the HtmlBuilder that implements all standard XHTML tags (see an overview of all available tags here).

class Home(XierpaBuilder):
Define the local applicaton class as inheritance of the XierpaBuilder. Now an instance of this Home class knows all tricks of the XierpaBuilder and the HtmlBuilder.
The we define an additional methods (=tags) for the Home class: build.
	def build(self):
		self.doctype('xhtml-transitional')
		self.html()
		self.head()
		self.title()
		self.text('Title of "Hello world" page')
		self._title()
		self._head()
		
		self.body()	
		self.text('Hello world')
		self._body()
		self._html()
Inside the definition of this build we can recognize the following tag calls.
		self.doctype('xhtml-transitional')
This creates a header with the type of HTML in the output page. The browser does use this information to anticipate the behavior of the page. There are several options, but currently the xhtml-transitional is the most obvious as the current browsers version are between HTML and XHTML. Later this could be changed.
		self.html()
		...
		self._html()
This creates the standard html tag.
		self.head()
		...
		self._head()
This creates the standard head tag.
		self.title()
		self.text('Title of "Hello world" page')
		self._title()
This creates the standard title tag.
		self.body()
		...
		self._body()
This creates the standard body tag.
Finally the text tag displays the only text line of this page.
		self.text('Hello world')
Let’s go to one step more complex