object20Object验证插件Flask [英] object20Object Validation plugin Flask

查看:159
本文介绍了object20Object验证插件Flask的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用验证jQuery插件与瓶框架。这是我的代码:

 电子邮件:{
required:true,
email:true,
remote:{
url:$ .getJSON($ SCRIPT_ROOT +/ _check_mail),
}
},
$ b $ p

这个请求应该发送到服务器,检查数据库中是否已经存在邮件yes或no:

 @ app.route('/ _ check_mail')
def check_mail():
mail = request.args.get('email')
check = database.check_mail(mail)
return check

如果检查变量是Trueif邮件不存在,并保存字符串这个邮件已经存在如果邮件已经存在。

然而,当我尝试发送这个服务器,我得到此错误消息:


  • 请求URL:http://0.0.0.0:5000 / [object%20Object]?email = arnoutaertgeerts%40gmail .com

  • 请求方法:GET

  • 状态码:404 NOT FOUN D



已经尝试了一些其他的东西,但没有任何工作。任何想法?

我想我可以使它与一个costum方法工作,但我需要做一个同步AJAX请求...

解决方案

我设法解决这个问题(现在是真实的)

.getJSON方法。这个方法是一个很简单的方法。

$ $ $ $ $ $ $ $ $ dataType:json,
url:url,
data:data,
success:success
});

这实际上已经被验证插件的远程调用所使用了!



所以我唯一需要做的是:

$ p $ email:{
required:true,
email:true,
remote:{
url:_check_mail,
data:{
email:function(){
返回$(#email)。val();
}
}
}
},


I'm trying to use the Validation jQuery plugin with the flask framework. This is my code:

email: {
    required: true,
    email: true,
    remote: {
        url: $.getJSON($SCRIPT_ROOT + "/_check_mail"),  
         }              
},

This request should get send to the servers that checks if the mail already exists in the database yes or no:

@app.route('/_check_mail')
def check_mail():
    mail = request.args.get('email')
    check = database.check_mail(mail)
    return check

The check variable is "True" if the mail doesn't exists and holds the string "This mail already exists" If the mail already exists.

However, when I try to send this to the server I get this error message:

  • Request URL:http://0.0.0.0:5000/[object%20Object]?email=arnoutaertgeerts%40gmail.com
  • Request Method:GET
  • Status Code:404 NOT FOUND

Already tried some other things but nothing worked. Any ideas?

I think I would be able to make it work with a costum method but then I need to do a synchronous AJAX request...

解决方案

I managed to fix it (now for real)

The problem was coming from the .getJSON method. This method is a short method for

$.ajax({
  dataType: "json",
  url: url,
  data: data,
  success: success
});

wich is actually already being used by the remote call of the validation plugin!

So the only thing I actually had to do was:

email: {
    required: true,
    email: true,
    remote: {
        url: "_check_mail",
        data: {
            email: function() {
                return $("#email").val();
                }
            }
         }
    },

这篇关于object20Object验证插件Flask的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆