Skip to content
Advertisement

How to accept None for String type field when using Flask-RESTPlus


I am just starting develop with flask-restplus and I am not a native speaker,

but I will try to describe my question as clear as I can.

I know there is a fields module in flask that help us define and filter response data type,

such as String, Integer, List and so on.

Is there any way to allow NULL / None when using fields module?

the following is my code that using field module to catch the value,

JavaScript

and if the data type of display_name is not String, there would be the following error raised,

JavaScript

what I want is when entering display_name, I can enter bulls or None


It seems few of the reference data / questions can be found, and I only found one result related

to my question, but eventually converting as non-null value to solve the issue.

if there is any part of my question not much clear,

please let me know, thank you.

the following is my develop environment:

flask-restplus 0.13.0 Python 3.7.4 postman 7.18.1


The following is my updated code:

JavaScript

if I input the following payload: (by postman)

JavaScript

It still returns:

JavaScript

Advertisement

Answer

Yes, you can create a child class and use it instead of default ones, which will accept None as well

JavaScript

So your code will look like

JavaScript

Additionally you can visit the issue github.com/noirbizarre/flask-restplus/issues/179

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement