例如,我在本地文件夹中有以下文件:
用户/网站/ ABC /照片/ 2012 / august.html 用户/网站/ ABC /照片/ 2012 / september.html
我想将这两个html页面上传到GAE并将URL设置为: (我们假设www.abc.com是我拥有的域名。)
http://www.abc.com/photos/august/ http://www.abc.com/photos/september/
我该怎么做?
以下是我目前的代码。我还没有办法解决它。
main.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)
的app.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"
答案 0 :(得分: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