推荐学习书目
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 · May 13, 2015 · 2528 views
    This topic created in 4022 days ago, the information mentioned may be changed or developed.
    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 replies    2015-05-13 13:28:57 +08:00
    redhatping
        1
    redhatping  
    OP
       May 13, 2015
    上面有错误, 不是dj框架, 是web.py
    bravecarrot
        2
    bravecarrot  
       May 13, 2015 via iPad   ❤️ 1
    用过django,点进来才发现是webpy,没用过webpy.
    模版不是jinjia2吗?
    v友们还是很友好的,没有喷你。

    建议:
    1.请把代码用markdown来写
    2.贴出详细的错误信息
    redhatping
        3
    redhatping  
    OP
       May 13, 2015
    @bravecarrot 好的,下次会注意,谢谢建议,非常受用
    redhatping
        4
    redhatping  
    OP
       May 13, 2015
    已经解决,对象的问题:
    $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>
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2756 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 00:03 · PVG 08:03 · LAX 17:03 · JFK 20:03
    ♥ Do have faith in what you're doing.