Am Dienstag, 11. Oktober 2016 14:16:50 UTC+2 schrieb Aymeric Augustin:
>
> Hello Sven,
>
> On 11 Oct 2016, at 14:07, Sven R. Kunze <srk...@gmail.com <javascript:>> 
> wrote:
>
> I took a sample of 4 of my colleagues and asked them what the problem with 
> expressions like {% if form.is_valid %} is. They have no idea. They said 
> "it might not make sense in some cases but when it makes sense, it doesn't 
> look very terrible me”.
>
>
> Can you show a non-contrived example, predating this discussion, of a 
> situation where this pattern make sense?
>


For displaying some error indicators, changing backgrounds to signal colors 
(like red), etc. I don't know what counts as a non-contrived example to you.

 

>
> So, what's the real problem here?
>
>
> The real problem is that templates aren’t the correct place to implement 
> business logic such as form validation.
>


I did never say "let's do business logic in templates". AFAIK, *displaying* 
errors (or preparing for it HTML-structure-wise) requires *knowing* whether 
a form is invalid or not.

When there's some logic to do, that's fine. But when some developer 
requires a simple boolean flag to know whether a form is valid or not, why 
shouldn't he use form.is_valid? That looks to me like making things more 
complicated than necessary.


Also, think about GET forms + AJAX which do not POST after redirect at all 
(e.g. search form + result table in separate AJAX containers). There you 
will re-use the same template for success and failure.

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/4ffb3d8c-43fa-4bc1-9762-eae79334af28%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to