问题
I want to save on a .ttl file a type 'person' resource from a javascript function:
this is my sparql query:
@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
and this is my javascript function with the ajax call:
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);
}
});
}
I don't know why it doesnt' work, any ideas?
回答1:
Your endpoint only accepts POST request: @app.route('/registraAnnotatore/<author>+<mail>', methods=['POST'])
and in your client you are doing a GET request method: 'GET',
That's why you're getting 405 METHOD NOT ALLOWED for this endpoint ( /registraAnnotatore/<author>+<mail>
).
来源:https://stackoverflow.com/questions/26236780/method-not-allowed-in-a-python-function-for-flask