V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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
redhatping
V2EX  ›  Python

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

  •  
  •   redhatping · 2015-05-13 10:57:35 +08:00 · 1953 次点击
    这是一个创建于 3278 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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-05-13 11:08:53 +08:00
    上面有错误, 不是dj框架, 是web.py
    bravecarrot
        2
    bravecarrot  
       2015-05-13 11:25:56 +08:00 via iPad   ❤️ 1
    用过django,点进来才发现是webpy,没用过webpy.
    模版不是jinjia2吗?
    v友们还是很友好的,没有喷你。

    建议:
    1.请把代码用markdown来写
    2.贴出详细的错误信息
    redhatping
        3
    redhatping  
    OP
       2015-05-13 11:30:28 +08:00
    @bravecarrot 好的,下次会注意,谢谢建议,非常受用
    redhatping
        4
    redhatping  
    OP
       2015-05-13 13:28:57 +08:00
    已经解决,对象的问题:
    $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>
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2203 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 02:04 · PVG 10:04 · LAX 19:04 · JFK 22:04
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.