- 论坛徽章:
- 0
|
本帖最后由 lonelysoul011 于 2013-02-05 17:23 编辑
主程序源码:- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- #print "Content-type: text/html\n"
- #print "Heloo"
- import web
- import blog
- import pos
- import guzhang
- #import connmysql
- from web import form
- urls = ('/','code',
- '/blog',blog.app_blog,
- '/pos',pos.app_pos,
- '/guzhang',guzhang.app_guzhang
- #'/pos/add',pos.app_pos
-
- )
- #'/pos',pos.app_pos
- render=web.template.render('templates/')
- class code:
- def GET(self):
- #return "Hello word!"
- return render.index()
-
- #+ path
-
- if __name__=='__main__':
- app = web.application(urls,globals())
- app.run()
-
复制代码 子程序源码- #print "Heloo"
- import web
- from web import form
- urls = (
- "","repos",
- '/(.*)','guzhang',
- '/add','add'
- )
- render=web.template.render('templates/')
- db=web.database(dbn='mysql',host='192.168.1.87',user='root',pw='123456',db='yunwei')
- class repos:
- def GET(self):
- raise web.seeother("/")
-
- class guzhang:
- def GET(self,path):
- s_guzhangs = db.select('guzhang')
- return render.guzhang(s_guzhangs)
- # return 'pos'
- class add:
- def POST(self,path):
- i = web.input()
- #d = web.input()
- n = db.insert('guzhang', find_time=i.find_time,do_time=i.do_time,all_time=i.all_time,what_happen=i.what_happen,result=i.result,_test=True)
- raise web.seeother('/')
-
- app_guzhang = web.application(urls,globals())
复制代码 templates 下guzhang.html 源码- $def with (s_guzhangs)
- <ul>
- <table border="1">
- <tr>
- <th>序号</th>
- <th>发现时间</th>
- <th>处理时间</th>
- <th>持续时间</th>
- <th>故障现象</th>
- <th>处理结果</th>
- </tr>
- $for s_guzhang in s_guzhangs:
- <tr>
- <td>$s_guzhang.id</td>
- <td>$s_guzhang.find_time</td>
- <td>$s_guzhang.do_time</td>
- <td>$s_guzhang.all_time</td>
- <td>$s_guzhang.what_happen</td>
- <td>$s_guzhang.result</td>
- </tr>
- </ul>
- <form method="post" action="add">
- <p>发现时间 <input type="text" name="find_time" /> <input type="submit" value="Add" /> </p>
- </form>
复制代码 启动方法:
[root@mqA cgi-bin]# ./code.py
http://0.0.0.0:8080/
参考web.py官方手册,在code 下直接运行可以Post 插入数据,使用子程序无法post 插入数据 。
错误信息:
[04/Feb/2013 17:23:04] "HTTP/1.1 POST /guzhang/add" - 405 Method Not Allowed
貌似官方手册post介绍不多。本人才接触web.py和python。
谢谢各位! |
|