使用Django验证Twitter引导程序

Validation Twitter Bootstrap with Django

本文关键字:引导程序 Twitter 验证 Django 使用      更新时间:2023-09-26

我正在使用Django和Twitter Bootstrap。我正在使用以下代码进行验证。但我想添加更多验证。例如,如果Django中的一个变量是false,则返回"所有者不存在"。我尝试了以下操作,但不起作用。

<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>

在服务器端,我这样做:

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

试试这个:

var test = {{msg_owner|safe}};