首页 新闻 会员 周边

python-flask 框架中的url_for

-1
悬赏园豆:10 [已解决问题] 解决于 2018-02-11 16:56

comments = []

@app.route("/", methods=["GET", "POST"])
def index():
   if request.method == "GET":
     return render_template("index.html", comments=comments)
   #如果是post:
   comments.append(request.form["contents"])
   return redirect(url_for('index'))

场景还原:我的服务器没开80端口,我用nginxlisten 81端口。利用flask框架(上述代码)遇到url_for('index')定向到 xxx.cn。可是我需要定向到 xxx.cn:81,那么应该怎么写?

(手动访问xxx.cn:81都是可以的。)

问题补充:

我的Nginx配置

server {
        listen 81;
        server_name 11.11.11.11; 

        location / {            
            proxy_pass http://127.0.0.1:5000; # 这里是指向 gunicorn host 的服务地址
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }       
}
Jneeee的主页 Jneeee | 菜鸟二级 | 园豆:230
提问于:2018-02-10 21:29
< >
分享
最佳答案
0

根据文章http://www.cnblogs.com/kevingrace/p/8073646.html 尝试添加proxy_redirect http://111111/ http://111111:81/;,还是不行。。。

Jneeee | 菜鸟二级 |园豆:230 | 2018-02-10 22:00

解决了!添加这句:

proxy_set_header Host $host:81;
Jneeee | 园豆:230 (菜鸟二级) | 2018-02-11 16:53
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册