谁能帮我解决这个问题,我的 javascript 有一个 ajax GET Http 请求:
$.ajax({
url:"/testPage",
type:'GET',
success: function(){
alert("done");
}
});
服务器端Python应用程序有一个处理程序来处理来自js的Http请求:
class testPageHandler(webapp.RequestHandler):
def get(self):
path=os.path.join(os.path.dirname(_file_).'page1.html')
template_values={}
self.response.out.write(template.render(path,template_values))
def post(self):
.....
application=webapp.WSGIApplication([('/testPage',testPageHandler),
.....
在“get”方法中,我希望渲染 Django 模板“page1.html”,以便浏览器显示“page1.html”页面,而不是仅仅弹出“done”。 任何想法?提前致谢。
最佳答案
Django 模板实际上被渲染并作为响应正文返回。现在您只想在客户端处理它。
$.ajax({
url:"/testPage",
type:'GET',
success: function(html){
$('body').append(html);
}
});
您可以按照您喜欢的任何方式操纵响应。在上面的示例中,它只是附加到 body
标记中。
关于javascript - 具有 ajax 请求和 python 交互的 Google 应用引擎,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9509191/