Friday, December 26, 2014

Re: Model form with optional fields issue

Hi Marcin,

It's very true that Django "forms" are very HTML specific. They are built for rendering html form inputs, interpreting raw browser POST data, and displaying errors as HTML.

An API isn't really "form". Validation and cleaning are already decoupled from "forms":


On Tuesday, December 23, 2014 4:44:54 AM UTC-6, wrote:

On Tuesday, December 23, 2014 3:49:07 AM UTC+1, James Schneider wrote:

Have you looked at the Django REST Framework module?

Yes, I have. They wrote own serializers and fields for validation, and they don't use builtin forms.
Personally I don't like DRF API, because it is too heavy and not following PEP20 (simple is better than complex), same as CBV in Django.

I wrote custom REST(-like) framework, independent from any framework but with bridge to Django. It's a little inspired by Cornice framework and I don't need (and don't want) to change it to Django REST Framework.

In my handlers I was using Django forms to clean & validate data, but they failed. I though that I've found bug, but now I see that I need to replace clean & validation to something better (maybe Colander).

Django is primarily used for displaying/validating data received from HTML forms

Now I know... I thought that Django is a generic web framework, but it isn't. It's a HTML-oriented web framework.

However, the internal behavior is decoupled enough

I disagree. It isn't decoupled enough for generic web framework:

1. Widgets are to close to fields (field.widget), and base Form class is using widgets directly in validation (field.widget.value_from_datadict calls in form`s methods).
2. Form._clean_fields() treats None value same as not existing key in input data - this is logical bug or improper simplification.

But in the context of validation only HTML fields this is OK.


You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
To view this discussion on the web visit
For more options, visit

No comments:

Post a Comment