开发者

Creating error messages with Django/Javascript

From the tutorial in djangobook.com http://djangobook.com/en/2.0/chapter07/, I am creating a form which returns error messages to the user if the required fields are not filled out.

How does Django create these error messages? Is it using python or jav开发者_如何学Goascript?

What is the best practice for creating error messages -- should I create them in django or using straight javascript? Thank you.


Yes, those error messages are being constructed on the Python side as Django is reconstructing your form page.

It's best to have server-side validation (on the Django side in your forms and form fields) and then add client-side as a progressive enhancement feature. Client-side validation is unreliable as there are many ways to get around it (disabling javascript, etc.) so you'll always need some kind of server side validation.

The jQuery validation plugin is a decent client-side javascript validation library if you're already using jQuery.


Without knowing what part of the djangobook are you referring (a link would be nice), I guess that probably you are referring to the validation that is done by django after checking the values retrieved in the POST or GET requests. Hence that validation is made with python in the server side.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜