On Thu, Jun 14, 2012 at 12:48 PM, Tomas Schertel <[email protected]> wrote: > What's the best way to populate fields of a page with database information. > Is it passing a database search result (from my controller) as a parameter > to my render call (calling my view)? > Is there other ways to do that? > How do you guys do it?
I'd get it to one DB row identified by the ID; e.g. "select from foo where id='id'". The id would be in the URL of the page to be displayed; e.g. foo?id=1234. Then my class that dealt with displaying that URL would get the id from web.input (check it for safety: http://xkcd.com/327/) and then run the query. The output of the query would then populate a dictionary mapping form field to form value; you could do this in a separate object which encapsulates the dictionary. I would then pass that dictionary (or an object with said dictionary encapsulated) to my render method. Render would call an HTML template which was populated using HTML like this: <input type=text name="something" value="$something"> That way if the form is empty $something doesn't display but if $something contains a value it will be the default value of your form. John -- You received this message because you are subscribed to the Google Groups "web.py" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/webpy?hl=en.
