0

我正在尝试从 python 迁移到 2.7 到 2.5,但是在对 main.py 和 app.yaml 文件进行了必要的更改后,我的网站无法运行

请帮助...我应该对这些进行哪些更改才能使其正常工作

主文件

import os
from google.appengine.ext import webapp

from google.appengine.ext.webapp import util

from google.appengine.ext.webapp import template

class MainHandler(webapp.RequestHandler):
  def get (self, q):
    if q is None:
      q = 'index.html'

    path = os.path.join (os.path.dirname (__file__), q)
    self.response.headers ['Content-Type'] = 'text/html'
    self.response.out.write (template.render (path, {}))

def main ():
  application = webapp.WSGIApplication ([('/(.*html)?', MainHandler)], debug=True)
  util.run_wsgi_app (application)

if __name__ == '__main__':
  main ()

应用程序.yaml

application: cool-gadgets    
version: 1    
runtime: python    
api_version: 1    

handlers:
- url: /robots.txt
  static_files: static/robots.txt
  upload: static/robots.txt

- url: /favicon.ico
  static_files: static/favicon.ico
  upload: static/favicon.ico

- url: /gadgets/disney.xml
  static_files: gadgets/disney.xml
  upload: gadgets/disney.xml

- url: /gadgets/wwe.xml
  static_files: gadgets/wwe.xml
  upload: gadgets/wwe.xml

- url: .*
  script: main.py

我对此进行的更改以迁移到 2.7

主文件

import os
from google.appengine.ext import webapp

from google.appengine.ext.webapp import util

from google.appengine.ext.webapp import template

class MainHandler(webapp.RequestHandler):
  def get (self, q):
    if q is None:
      q = 'index.html'

    path = os.path.join (os.path.dirname (__file__), q)
    self.response.headers ['Content-Type'] = 'text/html'
    self.response.out.write (template.render (path, {}))


  application = webapp.WSGIApplication ([('/(.*html)?', MainHandler)], debug=True)

应用程序.yaml

application: cool-gadgets    
version: 1    
runtime: python27    
api_version: 1    
threadsafe: true    

handlers:
- url: /robots.txt
  static_files: static/robots.txt
  upload: static/robots.txt

- url: /favicon.ico
  static_files: static/favicon.ico
  upload: static/favicon.ico

- url: /gadgets/disney.xml
  static_files: gadgets/disney.xml
  upload: gadgets/disney.xml

- url: /gadgets/wwe.xml
  static_files: gadgets/wwe.xml
  upload: gadgets/wwe.xml

- url: .*
  script: main.application
4

1 回答 1

2

请不要说“不起作用”。这没有提供有用的信息。你应该说你看到了什么,你得到了什么错误等等。

在您的情况下,您似乎最有可能遇到缩进​​错误:application末尾main.py需要完全靠左,因为它是模块级变量。

于 2013-06-04T10:42:27.627 回答