TurboGear学习笔记3
首先非常感谢JeffreyHsu~~~指出了我的问题~给了我很多帮助~~指明了方向~~非常非常感谢~^^~之前遗留下的save方法不能保存的问题.原因是出在了前台.
<div py:replace="wikipage.data">Page text goes here.</div>
本来应该改成这样的
<div><form action="/save" method="post"> <input type="hidden" name="pagename" value="${wikipage.pagename}"/> <textarea name="data" py:content="wikipage.data" rows="10" cols="60"/> <input type="submit" name="submit" value="Save"/></form></div>
但是我把 <input type="hidden" name="pagename" value="${wikipage.pagename}"/>
写成了 <input type="hidden" name="pagename" value="${wikipage.data}"/>
save总用data当成pagename取data,怎么可能找得到呢...
另外一个路径问题~
先在config目录下新建一个模块,我的建为routing.py.在config/app_cfg.py中
写下 from mac.config.routing import my_setup_routesAppConfig.setup_routes = my_setup_routes
将写路径的文件导入app_cfg.py
下面是routing里面的内容
from routes import Mapper#导入Mapperfrom tg.configuration import configdef my_setup_routes(self): """Setup the default TG2 routes Overide this and setup your own routes maps if you want to use custom routes. """ map = Mapper(directory=config['pylons.paths']['controllers'], always_scan=config['debug']) map.connect('/history', controller='history', action='routes_placeholder')#将/history URL 跟history controller联系起来,后面的无视之. # Setup a default route for the root of object dispatch map.connect('*url', controller='root', action='routes_placeholder') config['routes.map'] = map
下面是在history里面的方法,只是为了测试所以写得很简单
class HistoryController(BaseController): #Uncomment this line if your controller requires an authenticated user #allow_only = authorize.not_anonymous() @expose() def index(self): redirece("/admin/pages") @expose() def history(self): redirect("/admin/historys")
结果通过http://localhost:3000/history 能自动转向到http://localhost:3000/admin/historys,说明成功了.
但是为什么我只能用historycontroller里面的 history方法呢..?index方法为什么不能显示出来.....
再去找下文档再查
页:
[1]