0

例如,我在本地文件夹中有以下文件:

用户/网站/abc/photos/2012/august.html 用户/网站/abc/photos/2012/september.html

我想将这两个 html 页面上传到 GAE 并将 URL 设置为:(假设 www.abc.com 是我拥有的域。)

http://www.abc.com/photos/august/ http://www.abc.com/photos/september/

我怎样才能做到这一点?

以下是我目前的代码。我还没有找到解决它的方法。

主要.py:

import webapp2
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp import util
import os

class MainHandler(webapp2.RequestHandler):
    def get(self):
        template_values = {}
        path = os.path.join(os.path.dirname(__file__), 'index.html')
        self.response.out.write(template.render(path, template_values))

class August(webapp2.RequestHandler):
    def get(self):
        self.response.out.write(template.render('august.html',None))        

class September(webapp2.RequestHandler):
    def get(self):
        self.response.out.write(template.render('september.html',None))

def main():
    application = webapp2.WSGIApplication([
        ('/', MainHandler),
                ('august', August),
        ('september', September),
        ])
    util.run_wsgi_app(application)

app = webapp2.WSGIApplication([('/', MainHandler)],
                              debug=True)

应用程序.yaml

application: nienyihotw
version: 1
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /august
  static_files: august.html
  upload: august.html

- url: /september
  static_files: september.html
  upload: september.html

- url: /rootfolder
  static_dir: rootfolder

- url: /.*
  script: main.app

libraries:
- name: webapp2
  version: "2.5.1"
4

1 回答 1

1

你可以这样做:

class PhotosHandler(webapp2.RequestHandler):
    def get(self, year, month):
        path = os.path.join(os.path.dirname(__file__), 'photos', year, '%s.html' % month)
        self.response.out.write(template.render(path, None))

// delete the main
app = webapp2.WSGIApplication([('/', MainHandler), 
                               ('/photos/(.*)/(.*)', PhotosHandler)
                              ],
                              debug=True)

#app.yaml

handlers:
- url: /photos/.*
  script: main.app
于 2012-08-05T17:03:36.573 回答