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

web.py 如何设置模板中链接从新窗口打开?

  •  
  •   noah2132 · 2013-06-26 14:57:13 +08:00 · 3198 次点击
    这是一个创建于 3949 天前的主题,其中的信息可能已经有所发展或是发生改变。
    刚学web.py , 模板中
    <form action="/edit/$x.id" method="post">
    <input type="submit" value="edit" />
    <form>
    要如何做才能在点击“edit”后,在新窗口打开页面呢?
    第 1 条附言  ·  2013-06-26 16:29:26 +08:00
    report.py:

    import web
    import model

    render = web.template.render('templates', base='base')

    urls = (
    '/', 'index',
    '/report/(.*)', 'report'
    )

    class index:
    def GET(self):
    scanlog = model.get_scanlog()
    return render.scanlog(scanlog)

    class report:
    def POST(self, id):
    report = model.get_report(id)
    return render.report(report)

    if __name__ == "__main__":
    app = web.application(urls, globals())
    app.run()
    -----------------------------------------------------------------
    index.html模板:
    $def with (scanlog)
    <table>
    $for x in scanlog
    <tr>
    <form action="/report/$x.ScanID" method="post" tartget="_blank">
    <input type="submit" value="Report" />
    </form>
    </tr>
    </table>
    12 条回复    1970-01-01 08:00:00 +08:00
    shiny
        1
    shiny  
       2013-06-26 15:01:34 +08:00   ❤️ 1
    <form action="/edit/$x.id" method="post" target="_blank">
    noah2132
        2
    noah2132  
    OP
       2013-06-26 15:08:13 +08:00
    添加 target="_blank",先前试过了,不行啊。
    cj1324
        3
    cj1324  
       2013-06-26 15:11:47 +08:00
    我什么需要在form 中写 target, 这个属性应该写在 a标签中的~
    noah2132
        4
    noah2132  
    OP
       2013-06-26 15:31:29 +08:00
    @cj1324 form中不是也有这个属性么?
    noah2132
        5
    noah2132  
    OP
       2013-06-26 15:31:51 +08:00
    @shiny 请问还有没有别的办法?
    cj1324
        6
    cj1324  
       2013-06-26 15:39:45 +08:00
    form 是一个表单 你需要在表单提交的时候打开一个新的页面 还是在提交成功后打开新页面。
    flyingkid
        7
    flyingkid  
       2013-06-26 15:40:24 +08:00
    如果还有其他办法的那就是javascript了。
    cj1324
        8
    cj1324  
       2013-06-26 15:46:27 +08:00
    有一个叫onSubmit的事件 监听~
    noah2132
        9
    noah2132  
    OP
       2013-06-26 15:49:22 +08:00
    @cj1324 提交成功后
    qiayue
        10
    qiayue  
       2013-06-26 16:01:07 +08:00
    楼主需求没有描述清楚
    shiny
        11
    shiny  
       2013-06-26 16:03:57 +08:00
    1、这是 HTML,和 web.py 无关
    2、form 里 target="_blank" 我们每天线上在用,如果不能在新窗口中打开,需要自己检查下自己的页面了。
    noah2132
        12
    noah2132  
    OP
       2013-06-26 16:25:55 +08:00
    代码很简单,index.html页面时列表,点击每行的按钮,生成一个report.html,我就想生成的report.html是在新窗口打开,而不是直接从index.html页面打开。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3345 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 11:52 · PVG 19:52 · LAX 04:52 · JFK 07:52
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.