The first thing we'll need to do is create an __init__ method. The purpose of this is to accept attributes when an instance of our Product is created. In this example, we'll accept the attributes id, title and nickname: ... We can now add actual content to our Product. The methods that we create will be available as separate pages in our Product. These pages can be accessed by attaching the associated method's name to the id of the Product instance in a request (for example, http://localhost/instance/methodOne). We'll start with index_html, the default page that's called when nothing is specifically requested: ... def index_html(self): In the above method, we return a page that displays the instance's title and the value of the nickname attribute we accepted in the __init__ method earlier. Let's add one more method that lists data about an instance: ... def list_info(self):
blog comments powered by Disqus |