Sanic-ext question

Hi, everyone! Does sanic-ext have a validator method (as shown in the picture below) similar to Pydantic that allows me to implement more complex parameter verification? I didn’t find it in the sanic-ext document.

If you are passing the password in a json request body you can use pydantic for validation:

Thanks for answering my question! I want to use Reg to validate query params (not json format). Can sanic-ext handle this?

I don’t think that would use sanic-ext; you’d likely want to build a wrapper function for your route handler or use it specifically in your route. Also the only ‘Reg’ I could find that has to do with forms is synchronous, so you’d be introducing blocking calls into your application.

Yes, you could use this with pydantic models.

Thank you for replying to my question!

I wrote the code with reference to the sanic-ext tutorial. Then I found that when the parameter verification is wrong, my server will return the error message in HTML format, and the error log will appear on the server console (I don’t know whether the error log is normal).

The effect I want to achieve is that when the parameter verification fails, I can return the custom JSON format message containing error information through response, and the server console will not print the error log, but a normal log with status code 400.

The way I can think of is to implement a custom function for parameter verification in each request processing function, but obviously this is cumbersome. The processing method of sanic-ext is more convenient, but I don’t know how to achieve this effect through sanic-ext :sob:

This is my code.

This is what quiet=True does. See docs

I think what you probably want to do is to catch the exception and cast it as a custom error with quiet=True.