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

时间:2018-03-27 13:11:11

标签: python nginx flask 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,路径未更改为新网址

以下html文件在myserver.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的相对路径

1 个答案:

答案 0 :(得分:0)

我仍然没有解决这个问题,但我只是使用了url_for来表示我认为better

的所有链接
相关问题