python-flask 框架中的url_for

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;
        }       
}


收到一只叮咚
浏览 1584回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python