python bottle框架 运维_Python Bottle框架错误500:在守护进程模式下找不到模板

我目前正在使用bottle framework在Python中使用简单的webapp.这是我的应用程序结构:

结构体

lib

- bottle.py

- bottledaemon.py

- lockfile.py

- __init__.py

view

- dashboard.tpl

run.py

这是我的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()

所以我希望WSGI服务器通过将其传递给bottle daemon script来在守护进程中运行.

问题

运行非守护程序的代码时,它可以工作.它显示了正确的模板,在CLI中我可以看到HTTP请求.

但是,当我在守护进程模式下运行相同的代码时,它确实以守护进程启动,因此工作正常,但它无法再找到模板.它向我显示了这个错误信息:

Error: 500 Internal Server Error

Sorry, the requested URL ‘HERE IS MY WEBSITE URL’ caused an error:

Template ‘template’ not found.

因此,当我以守护进程模式启动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

编辑:

追溯到问题的根源,这肯定是一个路径问题. bottledaemon进口守护进程并运行DaemonContext,默认情况下将工作目录更改为’/’,而bottledaemon不会覆盖它应该如此.因此,当瓶子查找视图文件夹的相关路径时,它实际上是在系统的根目录中查找“/ view”.

标签:python,wsgi,bottle

来源: https://codeday.me/bug/20190528/1172409.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值