【发布时间】:2013-07-03 01:13:28
【问题描述】:
我按照 Pyramid 教程进行操作,一切正常。然后我为 Pyramid 安装了 jinja2 并将必要的代码行添加到我的 development.ini 文件中。按预期在指定位置找到了我的模板。它们也按照我的预期呈现。但是,在我的计算机上重新启动然后使用 Alembic 和 SQLAlchemy 后,我去查看我的站点,现在它没有找到模板目录。具体来说,我得到的错误是:
jinja2.exceptions.TemplateNotFound
TemplateNotFound: my_project:templates/index.jinja2;
asset=/Users/John/project/projectenv/lib/python2.7/site-packages/my_project-0.0-py2.7.egg/my_project/templates/index.jinja2;
searchpath=['/Users/John/project/projectenv/lib/python2.7/site-packages/my_project-0.0-py2.7.egg/my_project/templates']
在我指定的development.ini 文件中:
[app:main]
use = egg:my_project
jinja2.directories = my_project:templates
对于某些参考框架,我的文件结构如下所示:
/project
/projectenv
/bin
/development.ini
/lib # where the "python2.7/site-packages/etc." is located
/my_project
/my_project # "main" project folder
/__init__.py
/models.py
/scripts
/static
/templates
/<the templates I would like to use>
/views.py
两个问题:
- 我该如何解决这个问题?无论出于何种原因,我的资产规范无法正常工作,我不确定要“指定”什么来解决此问题。
- 当我查看
../python2.7/site-packages/my_project-0.0-py2.7.egg/my_project/templates时,我从我的“主”/my_project目录中找到了我的文件的“残余”。特别是,templates文件夹及其内容不存在,但views、models、__init__等存在(尽管这些文件的任何最新更新都不存在)。当我对“主要” my_project 文件进行更新时,Pyramid 无法识别这些更改。我需要进入我的“...2.7.egg”文件,并在那里进行更改以便 Pyramid 识别它们。为什么会这样?
我的development.ini 文件配置不正确吗?或者,这是完全不相关的事情吗?
我很困惑,不知道该怎么办。非常感谢任何想法、建议和直截了当的答案。
感谢您的帮助。
【问题讨论】:
-
你是如何渲染模板的?
-
在我的views.py文件中,例如:@view_config(renderer='templates/index.jinja2', route_name='index_handler')。然后我在我的 __init__.py 文件中添加路由。我也尝试在 __init__ 中添加“config.include('pyramid_jinja2')”,但无济于事。
-
试试这个:@view_config(renderer='index.jinja2',route_name='index_handler') 不需要'templates/'
-
我刚试了一下,很遗憾,没用。不过感谢您的建议!
标签: python pyramid jinja2 pylons