带有ajax请求和python交互的谷歌应用程序引擎

Google app engine with ajax request and python interactions

本文关键字:谷歌 应用程序 引擎 交互 python ajax 请求 求和 带有      更新时间:2023-09-26

有人能帮我解决这个问题吗?我的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标签上。

相关文章: