==================================== 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,