scr*_*www 4 python wsgi bottle
我目前正在使用瓶子框架在Python中使用简单的webapp .这是我的app结构:
结构体
lib
- bottle.py
- bottledaemon.py
- lockfile.py
- __init__.py
view
- dashboard.tpl
run.py
Run Code Online (Sandbox Code Playgroud)
这是我的run.py代码:
#!/usr/bin/env python
from lib.bottle import route, template, run, debug, request, static_file
from lib.bottledaemon import daemon_run
debug(mode=True)
@route('/')
def show_index():
return template('dashboard')
# If the following line is enabled, the server will start in non-Daemon mode.
#run(host='0.0.0.0', port=80, debug=True)
# If the following lines are enabled, the server will start in Daemon mode.
if __name__ == "__main__":
daemon_run()
Run Code Online (Sandbox Code Playgroud)
因此,我希望WSGI服务器通过将其传递给瓶子守护程序脚本来在守护程序中运行.
问题
运行非守护程序的代码时,它可以工作.它显示了正确的模板,在CLI中我可以看到HTTP请求.
但是,当我在守护进程模式下运行相同的代码时,它确实以守护进程启动,因此工作正常,但它无法再找到模板.它向我显示了这个错误信息:
错误:500内部服务器错误
抱歉,请求的网址"此处是我的网站网址"导致错误:
找不到模板"模板".
因此,当我以守护进程模式启动Web服务器时,看起来无法再找到.tpl文件的文件路径.我已经尝试了很多东西,但我无法理解它,我想保持路径动态.有什么建议吗?
谢谢!
这可能是路径问题,我能够通过手动将视图文件夹的路径添加到瓶子TEMPLATE_PATH列表来重新创建并修复它.
from bottle import route, template, run, debug, request, static_file, TEMPLATE_PATH
from bottledaemon import daemon_run
import os
TEMPLATE_PATH.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "view")))
# rest of script
Run Code Online (Sandbox Code Playgroud)
编辑:
追溯到问题的根源,这肯定是一个路径问题.bottledaemon导入daemon和运行DaemonContext默认情况下将工作目录更改为'/'并且bottledaemon不会覆盖它应该如此.因此,当瓶子查找view文件夹的相关路径时,它实际上是在系统的根目录中查找"/ view".
| 归档时间: |
|
| 查看次数: |
2382 次 |
| 最近记录: |