web.py中页面间传值的问题

新手上路,请多包涵

在code.py中声明如下数据库对象

db = web.database(dbn='mysql' , user='root' , pw='jackniang#2',db='YoO_database')

将数据库对象return到index.html模板

class index:
	def GET(self):
		notes = db.select('tab_note')
		return render.index(notes)

在index模板中接收

$def with (notes)

在页面遍历并通过超链接方式将单个记录结果传递给notepage页面

$for note in notes:
	<a href="/note?$note" >

请问,在note页面中应该如何接收?我已经试过用字典形式但是不行。

阅读 7.4k
1 个回答

note 页定义一个新的路由

urls = (
    '/', 'index',
    '/note/(.*)', 'Notepage'  # 超链接传入note
)

然后在Note控制器中获得地址栏传入的id

class Notepage:
    def GET(self, note):
        return render.notepage(note)

这样就能在notepage.html这个模板中调用了,跟你的index差不多

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题