#model:
db.define_table('dept',
Field('name',unique=True,label='Department Name'),
format='%(name)s')
db.define_table('course',
Field('dept_id','reference dept'),
Field('name',unique=True,label='Course Name'),
format='%(name)s')
db.define_table('files',
Field('course_id', 'reference course'),
Field('documentx_filename',unique=True),
Field('documentx','upload'))
#controller:
# list all departments
def show_dept():
rows = db().select(db.dept.ALL)
return dict(rows=rows)
def show_dept_course():
z = db(request.args(0) == db.dept.id).select()
courses = db(request.args(0) == db.course.dept_id).select()
return locals()
#view:(show_dept_course.html)
{{extend 'layout.html'}}
<h1>This is the x/show_dept_course.html template</h1>
<h3>
Name of dept:
</h3>
{{for x in courses:}}
<h3>
{{=x.name}}
</h3>
{{pass}}
{{=BEAUTIFY(response._vars)}}
in view if I leave
Name of dept = (empty)
everything works as expected but if I replace it with:
Name of dept:{{=z.name}}
I get error:
<type 'exceptions.AttributeError'> 'Rows' object has no attribute 'name'
where as in bottom
{{=BEAUTIFY(response._vars)}}
I can see under z that dept.name is displaying. I am not sure what I am doing wrong and how can I fix it?
这样尝试
Name of dept:{{=z[0].name}}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.