【发布时间】:2018-04-19 05:43:37
【问题描述】:
我有以下应用:
server.py
@app.route('/')
def main():
return render_template('index.html')
@app.route('/login')
def login():
return 'hey'
index.html
<body>
<form action="http://localhost:5000/login" , method="post">
<input type="submit" value="submit">
</body>
现在我运行 ngrok:
ngrok http 5000
在网络浏览器中输入地址(由 ngrok 生成)后,我可以看到带有按钮的 index.html 页面,但是当我按下按钮时,它会将我重定向到 http://localhost:5000/login,我可以看到:“连接被拒绝”。 我的问题是如何设置 ngrok 和烧瓶服务器的通信方式?
附:为了更好地阅读,我只放了一部分代码
【问题讨论】:
-
更简单的是,使用
pyngrok(pip install pyngrok) 直接在您的server.py中调用和管理ngrok。 Here's a full Flask example,但基本上你只需要from pyngrok import ngrok,然后在定义路由时ngrok.connect(5000)。