我正在使用 Cookiecutter Pyramid Web 开发框架。这有三个链接文件:
utils.py - 定义要添加到 url 的随机缓存字符串
views.py - 将 utils 函数传递给 chameleon 模板
layout.pt - 调用静态 css url 等的变色龙模板。
在 layout.pt pre-cache-busting 中有一个链接说:
<link href="${request.static_url('pycharm_app:static/theme.css')}" rel="stylesheet">
我正在尝试编辑此链接以调用 build_cache_id 函数:
<link href="/static/theme.css?cacheId=${build_cache_id('/static/theme.css')}" rel="stylesheet">
但得到错误:
NameError: build_cache_id
- Expression: "build_cache_id('/static/theme.css')"
- Filename: ... s/first_business_website/pycharm_app/templates/layout.pt
- Location: (line 17: col 43)
- Source: ... ss?cacheId=${build_cache_id('/static/theme.css')}" rel="styl ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Expression: "load: layout.pt"
- Filename: ... rst_business_website/pycharm_app/templates/mytemplate.pt
- Location: (line 1: col 22)
- Source: <div metal:use-macro="load: layout.pt">
^^^^^^^^^^^^^^^
- Arguments: view: <function my_view at 0x109eff8b0>
renderer_name: ../templates/mytemplate.pt
renderer_info: <RendererHelper - at 0x109f3f040>
context: <DefaultRootFactory None at 0x109d3faf0>
request: <Request - at 0x109d3fa90>
req: <Request - at 0x109d3fa90>
get_csrf_token: <partial - at 0x109f32db0>
project: pycharm_app
target_language: <NoneType - at 0x10817de60>
repeat: {...} (0)
macroname: load: layout.pt