Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The best way to validate form-data in tornado project?

I need to validate data in my tornado project (pure-tornado including static pages, no django application)

There are 2 situations: 1) validate JSON-object obtained by the HTTP-API or WS 2) validate data from page form transmitted in the HTTP request (RequesHandler)

What to do? Use Django FORMS? Or maybe something else, it is best suited to this situation? what do you say?

like image 270
Roosh Avatar asked Jul 18 '13 06:07

Roosh


1 Answers

I suggest WTForms for handing form submissions, there are numerous posts about how to go about that an example is on the Google group here and a stackoverflow answer here. WTForms requires that the request data be in a specific information and the above links state that and give examples on how to achieve this format.

But, from part of the question it looks like you are also wanting to check JSON input from api requests. For this I would recommend schema. The schema library provides a method to validate input such as a dict or in your case the json input. It will raise and error if the data does not conform to your rules.

like image 161
sean Avatar answered Sep 19 '22 20:09

sean