【发布时间】:2018-12-02 21:05:28
【问题描述】:
我将 Bottle 用于 Python 项目,并将项目设置为在 localhost:8080(Windows 10 笔记本电脑)上运行。我已经在 VS Code 上对项目进行了编码,但是,当我在 VS Code 的集成终端上启动调试器时,我的浏览器(Google Chrome)上出现错误 500。
该项目在 TA 的机器上运行良好,但在我的笔记本电脑上,bottle 没有路由到索引页面,即使我明确让它从 static_file 导入它并将根文件添加到“运行”功能。我尝试从 Bottlepy.org 运行示例,但还是不行。
唯一有效的是:
from bottle import run, route
@route('/')
def hello():
return "If you're seeing this message, then bottle is working"
run(host='localhost', port=8080)
我又跑了:
from bottle import run, route, template
@route('/')
def hello():
return template("index.html")
run(host='localhost', port=8080)
和
from bottle import run, route, static_file
@route('/static/')
def hello():
return static_file('index.html', root='static')
run(host='localhost', port=8080)
包括来自 bottlepy.org 的示例,结果如下:
Error 500 Template 'index.html' not found.
或者
Error 500 ‘Template ‘/’ not found
我不认为这是 Python 的 PATH 问题,但它可能是 VS 代码的 JSON 文件问题。我机器上的所有 Python 包都已更新,目前我没有想法。您的建议/建议将不胜感激。谢谢。
【问题讨论】:
-
可能是路径问题。您可以从
hello中打印 cwd 吗? -
'hello' 中的 cwd?你能澄清你的问题吗?我对 Python 比较陌生。