some ideas:
use len(a), so if there is not a then len = 0
use templates with True or False, because then it's True, the value
will be 1 and in strings, "word"*1="word", else it will be an empty
string: "word"*0=""
use Raise to raise an error.
On 3 nov, 18:06, Nick Baum <
nickb...@whereberry.com> wrote:
> Hi,
>
> I'm looking for advice on to how to best implement form validation in
> Tornado.
>
> My original pseudo code went something like
>
> def post(self):
> a = self.get_argument("a")
> b = self.get_argument("b")
> [...]
> db.doStuff(a, b)
> self.render("success.html")
>
> def write_error(self, status_code, **kwargs):
> self.render("template.html", error=status_code)
>
> This was nice and clean because get_argument throws exceptions if an
> argument was missing.
>
> Unfortunately, two things are wrong with it:
>
> - There's no easy way to know what argument was missing when rendering
> the error (short of parsing the error message), so there's no way to
> display the error next to the corresponding form field
> - An error loses all the entered information, unless I parse all the