woshichuanqilz
V2EX  ›  Flask

flask 运行的时候如何直接打开一个链接?

  •  
  •   woshichuanqilz · Jan 30, 2018 · 4118 views
    This topic created in 3025 days ago, the information mentioned may be changed or developed.

    就是比如在这个窗口之后

    20180130112133

    我想让浏览器直接打开一个网页比如, 127.0.0.1

    11 replies    2018-01-31 11:27:17 +08:00
    est
        1
    est  
       Jan 30, 2018
    import webbrowser
    est
        2
    est  
       Jan 30, 2018
    webbrowser.open_new_tab("http://127.0.0.1:5000")
    julyclyde
        3
    julyclyde  
       Jan 30, 2018
    @est 进程会卡在上述步骤,不会执行到你这一句的
    你这一句得另外开个 thread 来执行
    cbiqih
        4
    cbiqih  
       Jan 30, 2018
    Edit configurations 中勾选 Run browser
    wellsc
        5
    wellsc  
       Jan 30, 2018
    如果是 macOS 的话 flask 程序入口加一个 import os;os.popen('open -a "/Applications/Google Chrome.app" {}'.format("localhost:5000")).close()
    wellsc
        6
    wellsc  
       Jan 30, 2018
    域名要加上 http://
    seanzhao
        7
    seanzhao  
       Jan 30, 2018
    那你得打开 80 端口
    woshichuanqilz
        8
    woshichuanqilz  
    OP
       Jan 30, 2018
    v2xe2v
        9
    v2xe2v  
       Jan 30, 2018
    前后端分离吧
    julyclyde
        10
    julyclyde  
       Jan 30, 2018
    @woshichuanqilz 因为不是 flask 里的
    cbiqih
        11
    cbiqih  
       Jan 31, 2018
    我是用 Pycharm 开发,运行设置里有这个选项
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3363 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 72ms · UTC 11:21 · PVG 19:21 · LAX 04:21 · JFK 07:21
    ♥ Do have faith in what you're doing.