Python BAE部署web.py 应用

1、requirements.txt :

web.py==0.37
MySQL-python==1.2.4

2、index.py:

#-*- coding:utf-8 -*-

import web


"URL配置"
urls = (
	 "/", "index",
	 "/list", "list",
	 "/add", "add"
)

"设置模板"
render = web.template.render('templates/')

"数据库"
db = web.database(dbn='mysql', user='API Key', pw='Secret Key', db='数据库', host='sqld.duapp.com', port=4050, charset='utf8')


class index:
	def GET(self):
		i = web.input(name=None)
		return render.index(i.name)

class list:
	def GET(self):
		users = db.select('webpy_users')
		return render.list(users)


class add:
	def POST(self):
		i = web.input()
		n = db.insert('webpy_users', id=i.id, name = i.name)
		raise web.seeother('/list')	#重定向


app = web.application(urls, globals()).wsgifunc()

from bae.core.wsgi import WSGIApplication
application = WSGIApplication(app)

3、app.conf:

handlers:
  - url : /
    script: index.py
  - url : /add
    script: index.py
  - url : /list
    script: index.py

  - expire : .jpg modify 10 years
  - expire : .swf modify 10 years
  - expire : .png modify 10 years
  - expire : .gif modify 10 years
  - expire : .JPG modify 10 years
  - expire : .ico modify 10 years

 

发表评论