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
tangyuan
V2EX  ›  Python

python bottle 如何将sqlite数据库中获取到的数据在view的html页面中显示出来呢?

  •  
  •   tangyuan · 2013-02-03 22:03:42 +08:00 · 5073 次点击
    这是一个创建于 4108 天前的主题,其中的信息可能已经有所发展或是发生改变。
    返回的是list对象,但是我像在python中一样遍历该对象试图将其显示出来但缺失败了,直接打印出来的是一串 i...

    %for i in result:
    <p>i</p>
    %end
    12 条回复    1970-01-01 08:00:00 +08:00
    luztak
        1
    luztak  
       2013-02-03 22:05:39 +08:00   ❤️ 1
    {{i}}
    tangyuan
        2
    tangyuan  
    OP
       2013-02-03 22:06:42 +08:00
    @luztak 太感谢了!
    tangyuan
        3
    tangyuan  
    OP
       2013-02-03 22:11:43 +08:00
    @luztak luz再麻烦你一下,请问bottle里面有类似php中用?符号在url中传值?para的方法吗?我已经按照你之前的提示动态将url生成好了,现在需要提取其中的id部分传到另外一个页面中去
    ericFork
        4
    ericFork  
       2013-02-03 22:14:23 +08:00   ❤️ 1
    @app.route("/get/<param>")
    def get_some(param):
    return "param: %s" % param
    tangyuan
        5
    tangyuan  
    OP
       2013-02-03 22:14:49 +08:00
    http://127.0.0.1:8080/update/20130203174407

    上面这个url中‘20130203174407’是动态生成的部分,想抓住它貌似bottle里面的url比php干净的多...
    tangyuan
        6
    tangyuan  
    OP
       2013-02-03 22:19:33 +08:00
    @ericFork got it! 这下关键点都知道其他的就是体力活啦~
    luztak
        7
    luztak  
       2013-02-03 22:35:22 +08:00
    @tangyuan 不好意思 刚才转别处去了 不知道...
    php的是get/post传参 get长了会很难看
    python是从url解析就开始分配
    php被限制了
    .htaccess也能实现不过比较麻烦
    (有种班门弄斧的感觉- -||
    tangyuan
        8
    tangyuan  
    OP
       2013-02-05 00:44:37 +08:00
    @luztak 感谢您!再多问个问题,如果要想插入一段html代码应该如何做呢?譬如我这样:

    .html里面:{{t}}

    .py里面 t = '<input type="button" value="Update" />',并且将t传入到template中去

    但是程序运行后html页面中显示的就是这个字符串 '<input type="button" value="Update" />',并未将其转换成html button
    Sin
        9
    Sin  
       2013-02-05 00:56:38 +08:00   ❤️ 1
    也许是 {{!t}} 吧
    Sin
        10
    Sin  
       2013-02-05 00:58:18 +08:00
    建议参考这个……
    SimpleTemplate Engine
    http://bottlepy.org/docs/dev/stpl.html
    tangyuan
        11
    tangyuan  
    OP
       2013-02-05 01:01:23 +08:00
    @Sin 太感谢了,就是方才没有在文档中找到,原来如此简单,感谢感谢
    ericFork
        12
    ericFork  
       2013-02-05 01:27:49 +08:00
    少年,仔细读文档吧……

    https://github.com/myzhan/bottle-doc-zh-cn 这里还有份中文的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1063 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 18:17 · PVG 02:17 · LAX 11:17 · JFK 14:17
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.