Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Django Authentication Authentication LogoutView and SignUpView

Send the validation errors as JSON data.

What if I want to send the validation errors of the sign up/registration form as JSON data, so that it can be accessible to all platforms like: Android, IOS, Web. Also, in general what is the way to send any type of validation errors as JSON data.


Suppose I am building a registration/signup or any form in general for my web app in Django and I want the same form for Web/Android/IOS. So I want the frontend and backend(Django) to communicate via JSON. My question is how can I send validation errors in JSON format if the user on any platform(Web/Android/IOS) gives me invalid data like "the email already exists" type of errors?

Kenneth Love

1 Answer

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Generally you want to use an API instead of HTML views for mobile apps, so I'd suggest checking out Django REST Framework (we have a course here, in fact) and using that as the sign up/login/etc endpoint for submitting the forms to. That means you can build your frontend in JavaScript or something if you want.