简体   繁体   中英

How do I make User fields required in Django Rest Framework?

I'm trying to use the Default User Model in Django for a REST API but I don't know how to make fields like first_name, last_name, email required when people register. Would I have to use a custom User model or is this something that can be taken care of in the view?

I assume you are using HTML for your view. Then you can add the required attribute on an input tag. Further you can spice it up with css.

Take a look at: http://www.w3schools.com/tags/att_input_required.asp

I decided to go with a custom user model. This will allow me to add more fields if I need to anyways. I found the following thread that helped me design my custom user model: https://groups.google.com/forum/#!topic/django-rest-framework/BlxIeI6nHXo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM