在Pyramid中渲染Mako模板时出现未知谓词值错误

1 投票
1 回答
678 浏览
提问于 2025-04-17 21:04

我在渲染mako模板的时候遇到了ConfigurationError('未知的谓词值: %r' % (kw,))的错误。下面是我这个pyramid项目的结构。

我的pyramid项目目录结构。

|-- web
|-- myweb
    |-- templates
        |-- index.mak
    |-- __init__.py
    |-- views.py
|-- development.ini
|-- production.ini

web/myweb/views.py

class Main(object):
def __init__(self, request):
    self.request = request
def __call__(self):
    return {}

web/myweb/__init__.py

config.add_route('main', '/',
                 view='myweb.views.Main',
                 renderer='index.mako')

我在这里遇到了这样的错误:

 raise ConfigurationError('Unknown predicate values: %r' % (kw,))
 pyramid.exceptions.ConfigurationExecutionError: <class   pyramid.exceptions.ConfigurationError'>: Unknown predicate values: {'renderer': 'index.mako', 'view': 'myweb.views.Main'}
  in: Line 33 of file /home/user/project/web/myweb/__init__.py:
renderer='index.mako')

这是我的.ini文件

development.ini

[app:myweb]
mako.directories = web:myweb:templates

production.ini

[app:myweb]
mako.directories = web:myweb:templates

我不知道我缺少了什么,导致了这个错误。

1 个回答

0

显而易见,__init__.py 是指模板 "index.mako",而这个文件的名字叫 "index.mak"。

撰写回答