在同一进程中托管多个应用程序(flask、nginx 和 uwsgi)

Hosting multiple apps in the same process (flask, nginx, and uwsgi)

在安装点 (http://uwsgi-docs.readthedocs.io/en/latest/Nginx.html#hosting-multiple-apps-in-the-same-process-aka-managing-script-name-and-path-info) 下托管应用程序时,即:myserver.com/home --> myserver.com/myproject/home,路径不会更改为新的 URL

以下html个文件在我的服务器下呈现。com/myproject/* home.html

This is <a href='/home'>HOME</a>   
#<!-- page is linked to myserver.com/home instead of myserver.com/myproject/home -->
Please login <a href='/login'>HERE</a> 
#<!-- page is linked to myserver.com/login instead of myserver.com/myproject/login -->
{{ request.path }} 
#<!-- will display myserver.com/home -->

login.html

<form action='/login' method='post'>
<input type='text' name='username'>
<input type='password' name='password'>
<input type='submit'>
</form>
#<!-- post request is submitted to myserver.com/login instead of myserver.com/myproject/login -->

main.py=烧瓶路线

@app.route('/home')
return render_template('home.html')
@app.route('/login')
return render_template('login.html')

这是我的目录结构:

myproject/
|__app/
|____main.py
|____static/        #js and css are located (working)
|____templates/     #html files are located
|________home.html #page is rendered but relative links are still pointing to old URL
|________login.html
|__venv/            #virtual environment
|__run.py           #uwsgi module
|__myproject.ini      #set mount = /myproject=run.py
|__myproject.sock

更新:刚刚发现 request.script_root 与 request.path

的区别

谁能帮我把相对路径设置成request.script_root

我仍然没有解决这个问题,相反,我只是对我认为是 better

的所有链接使用了 url_for