flas的python函数中的“method not allowed”

2024-10-02 18:19:12 发布

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

我想在.ttl文件中保存来自javascript函数的类型“person”资源:

这是我的sparql查询:

@app.route('/registraAnnotatore/<author>+<mail>', methods=['POST'])
    def registraAnnotatore(author,mail):
    sparql = SPARQLWrapper("http://localhost:3030/data/update")
    mailto = "<mailto:"+mail+">"
    sparql.setQuery("""
        PREFIX  aop: <http://vitali.web.cs.unibo.it/AnnOtaria/person/>
        PREFIX  foaf: <http://xmlns.com/foaf/0.1/>
        PREFIX  schema: <http://schema.org/>

    INSERT DATA
    { """+mailto+""" a foaf:Person;
      foaf:name """+author+""";
      schema:email """+mail+""".
    }

     """)
    sparql.setReturnFormat(JSON)
    results = sparql.query().convert()
    results = results['results']['bindings']
    results = json.dumps(results)

    return results 

这是我的javascript函数和ajax调用:

 function salvaRemoto(){

    $.ajax({
     method: 'GET',
     url: '/verificaAnnotatore/'+fullname+'+'+email,
     success: function(d) {
     d = JSON.parse(d);
     alert(d.length);
     if(d.length>0){
         }else{
     //registrazione nuovo utente
     $.ajax({
        method: 'POST',
        url: '/registraAnnotatore/'+fullname+'+'+email,
        success: function() {   
        alert("Utente registrato !!!");

        },
        error: function(a,b,c) {

        alert(a + ' ' + b + ' ' + c);
       }
      });
     } 

    },
    error: function(a,b,c) {
    alert(a + ' ' + b + ' ' + c);
    }
   }); 
  }

我不知道为什么不行,有什么想法吗?你知道吗


Tags: httpprefixemailschemaajaxfunctionmailalert
1条回答
网友
1楼 · 发布于 2024-10-02 18:19:12

您的端点只接受POST请求:@app.route('/registraAnnotatore/<author>+<mail>', methods=['POST']),而在您的客户机中您正在执行GET请求method: 'GET',

这就是为什么这个端点不允许使用405方法(/registraAnnotatore/<author>+<mail>)。你知道吗

相关问题 更多 >