我编写了一个 ajax 代码来将值传递给 python 文件。我使用了 request.GET['user'] 但它给出了编译错误。帮助我在 python 中给出任何方法来捕获值。下面是python代码:
if (request.session.get('word',None) and request.session.get('user',None)):
print "<script type='text/javascript'>console.log('no words submitted')</script>"
else:
word=request.GET['word']
user=request.GET['user']
阿贾克斯代码:
$.ajax({
type:'GET',
url: "http://sudhanshu-gupta-gh.com/wm-mrg/word_to_dictionary_test.py",
data: {word: word, user: myName},
success:function(html) {
console.log("Word send");
},
error: function(){
console.log("Unable to Load!");
},
complete: function(){
console.log("Word Added")
}
});
编译错误:
File "word_to_dictionary_user.py", line 8, in <module>
word=request.GET['word']
NameError: name 'request' is not defined