redhatping
V2EX  ›  Python

dj 框架,sqlite3 下的页面报错问题。

By redhatping at 2015 年 5 月 13 日 · 2800 次点击
app.py 代码如下:

import web

urls = ('/','Index')
db = web.database(dbn='sqlite',db='movesite.db')

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

render = web.template.render('templates/')

class Index:
def GET(self):
movies = db.select('move')


return render.index(‘movies’)

if __name__ == '__main__':
app.run()

INDEX.HTML 代码如下:
$def with (movies)
<html>
<head>
<meta charset="UTF-8">
<title>hello world</title>
</head>
<body>
<h1>豆瓣movies</h1>

$movies['name']
</body>
</html>

页面发生错误, 提示indexError

我估计错误的代码在? $movies['name']

怎么调用数据库传输的数据呢?
4 条回复  •  2015-05-13 13:28:57 +08:00
redhatping
   1
redhatping  
OP
   2015 年 5 月 13 日
上面有错误, 不是dj框架, 是web.py
bravecarrot
   2
bravecarrot  
   2015 年 5 月 13 日 via iPad   ❤️ 1
用过django,点进来才发现是webpy,没用过webpy.
模版不是jinjia2吗?
v友们还是很友好的,没有喷你。

建议:
1.请把代码用markdown来写
2.贴出详细的错误信息
redhatping
   3
redhatping  
OP
   2015 年 5 月 13 日
@bravecarrot 好的,下次会注意,谢谢建议,非常受用
redhatping
   4
redhatping  
OP
   2015 年 5 月 13 日
已经解决,对象的问题:
$def with (movies)
<html>
<head>
<meta charset="UTF-8">
<title>hello world</title>
</head>
<body>
<h1>豆瓣movies</h1>

<ul>
$for movename in movies:
<li>$movename.name</li>
</ul>

</body>
</html>
推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
© 2026 V2EX · 32ms · 3.9.8.5