【问题标题】:Bottle.py MVC "Template not found."Bottle.py MVC“找不到模板。”
【发布时间】:2016-01-26 03:24:36
【问题描述】:

我想达到什么目的:

下面是我试图从 \mongodb\blog\blog.py 运行的代码

@bottle.route('/')
def blog_index():

cookie = bottle.request.get_cookie("session")

username = sessions.get_username(cookie)

return bottle.template('blog_template',username=username))

从终端运行 blog.py 并浏览到 localhost:8082 后,我收到以下错误:

找不到模板“blog_template”。

上周我遇到了类似的问题,我通过将文件夹权限更改为 777(只是为了排除权限问题)解决了这个问题,但目前所有子文件夹的权限都设置为上帝,我仍然得到相同的结果问题。

模板都位于 \mongodb\blog\views 中,如 bottle.py 文档中指定的那样

当前对该文件夹的权限如下:(regulator 是我登录时使用的用户

-rwxrwxrwx 1 regulator regulator  718 Mar 23  2015 blog_template.tpl
-rwxrwxrwx 1 regulator regulator 1211 Mar 23  2015 entry_template.tpl
-rwxrwxrwx 1 regulator regulator  113 Mar 23  2015 error_template.tpl
-rwxrwxrwx 1 regulator regulator  816 Mar 23  2015 login.tpl
-rwxrwxrwx 1 regulator regulator  581 Mar 23  2015 newpost_template.tpl
-rwxrwxrwx 1 regulator regulator 1454 Mar 23  2015 signup.tpl
-rwxrwxrwx 1 regulator regulator  368 Mar 23  2015 welcome.tpl

我很肯定这是一个基于权限的问题,并且我忽略了一些非常基本的问题,但由于我在过去 3 小时内一直在解决这个问题,我希望能有一些新的眼睛来看看它。

bottly.py 需要具备哪些权限才能工作?这是否记录在任何地方(我查看了http://bottlepy.org/docs/ 找不到此信息)?

--------------------编辑-------

自从写这篇文章以来,我还尝试了以下方法

我已经重新创建了一个新的测试项目来测试只有模板部件文件夹结构是

测试 |_test.py |_views |__test.tpl

  • 我已尝试将其作为 SUDO 运行,而没有 sudo。
  • 所有文件夹权限均为 777

test.py中的代码如下

from bottle import route, run, template

@route('/hello')
def hello():
    ##return "<h1>Hello World!</h1>"
    output = template('test')
    return output
run(host='0.0.0.0', port=8080)

权限

regulator@HP-EB8460p-UbGnome:/mongodb$ ls -l /mongodb/test/*
-rwxrwxrwx 1 root root  191 Jan 25 19:10 /mongodb/test/test.py

/mongodb/test/views:
total 4
-rwxrwxrwx 1 root root 141 Jan 25 19:12 test.tpl

最后是 .tpl 文件夹

<!DOCTYPE html>
<html>
<head>
<title>Why wont I work!!</title>
</head>
<body>
<h1>THIS IS A TEST</h1>
IF YOU CAN SEE THIS THE TEST WORKS!!!
</body>
</html>

【问题讨论】:

    标签: linux python-3.x permissions bottle


    【解决方案1】:

    也许您没有更改 TEMPLATE_PATH?

    bottle.TEMPLATE_PATH += './mongodb/blog/views' #change this to the place your templates are found in
    

    希望对你有帮助

    【讨论】:

    • 谢谢,不,很遗憾这并没有解决问题!
    • @WarrenGardner - 也许用一个小的工作示例来更新你的帖子?
    • 好吧,上周工作的那个没有工作,所以我无法发布一个工作示例。我将在我的 shudders Windows 机器上安装 bottle.py,因为文件夹权限应该不是问题
    猜你喜欢
    • 2019-04-28
    • 2012-02-22
    • 1970-01-01
    • 2015-04-08
    • 2018-01-02
    • 2012-07-10
    • 2015-03-14
    • 2020-06-13
    • 2021-05-28
    相关资源
    最近更新 更多