我的表单验证器之间不匹配(python中的len和javascript中的length)

2024-04-26 09:26:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我在后端使用formencode作为验证和表单生成包。在前端,我使用require.js

后端:

class RatingOnLocation(Schema):
    filter_extra_fields = True
    allow_extra_fields = True

    rating_text = validators.UnicodeString(not_empty=True, max=2000, strip=True)
    rating = validators.Int(not_empty=True, min=1, max=5)

前端:

init = function () {

        // Add Validation rules to the review form
        $form.validate({
            rules: {
                rating_text: {
                    required: true,
                    maxlength: 2000
                }

验证过程有些混乱,因为通过调试,javascript中的文本长度为2000,而python中的len为2012

你知道这是怎么回事吗?我想可能是编码问题

顺便说一下,我使用的是Python2.7


Tags: textformtrue表单fieldsjsnotrequire