==================================== Creating Objects Based on Form Input ==================================== What if we wanted the user to be able to designate which Natural object was instantiated for display on this web page? This is a very common need when implementing things like a database search form, where the user's search terms need to be provided as inputs to the object that will return the search results. The answer is given in the main Grok tutorial: if you can write your ``update()`` method so that it takes keyword parameters, they will be filled in with any form parameters the user provides. Rewrite your ``app.py`` to look like: .. code-block:: python import grok, random from transient.natural import Natural class TransientApp(grok.Application, grok.Container): pass class Index(grok.View): def update(self, n=None): self.badnum = self.num = None if n: try: self.num = Natural(int(n)) except: self.badnum = n And make your ``app_templates/index.pt`` look like: .. code-block:: html

This does not look like a natural number: “string

You asked about the number x!
It is prime. Its prime factors are: f,

Choose a number:
This time, when you restart your Grok instance and look at your application front page, you will see a form asking for a number:: Choose a number: __________ [Go] Enter a positive integer and submit the form (try to choose something with less than seven digits to keep the search for prime factors short), and you will see something like:: You asked about the number 48382! Its prime factors are: 2, 17, 1423 Choose a number: __________ [Go] And if you examine the URL to which the form has delivered you, you will see that the number you have selected is part of the URL's query section: http://localhost:8080/app/index?n=48382 So none of these numbers get their own URL; they all live on the page ``/app/index`` and have to be selected by submitting a query to that one page.