简体   繁体   English

使用Django验证Twitter Bootstrap

[英]Validation Twitter Bootstrap with Django

I am using Django and Twitter Bootstrap. 我正在使用Django和Twitter Bootstrap。 I am using the following code for validation. 我正在使用以下代码进行验证。 But I would like to add more validations. 但我想添加更多验证。 For example if a variable from Django is false to return 'Owner does not exist'. 例如,如果来自Django的变量为false ,则返回“所有者不存在”。 I tried the following but is not working. 我尝试了以下操作,但不起作用。

<script type="text/javascript">
var test = {msg_owner|safe}
$(document).ready(function() {
    $('#frm').bootstrapValidator({

        message: 'This value is not valid',
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            'owner': {
                validators: {
                    notEmpty: {
                        message: 'Please enter the Owner'
                    }
                    test==false: {
                        message: 'Owner does not exist'
                    }
                }
            }
        });
    });
</script>

In the server side I do this: 在服务器端,我这样做:

def test(request):
    msg_owner = False
    return render_to_response("hello.html", {'msg_owner': msg_owner})

尝试这个:

var test = {{msg_owner|safe}};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM