2013-03-27 89 views
-1
使用代碼塊時獲得builtins.NameError

我預計這個片段的工作:在變色龍

<div class="footer"> 
    <? python import time; year = time.strftime('%Y') ?> 
    &copy; Copyright 2008-${year}, Agendaless Consulting. 
</div> 

相反,它失敗:

NameError: year 

- Expression: " python import time; year = time.strftime('%Y') ?> 
     &copy; Copyright 2008-${year}, Agendaless Consulting." 
- Filename: /tmp/foo/foo/foo/foo/templates/mytemplate.pt 
- Location: (74:8) 
- Source:  ... python import time; year = time.strftime('%Y') ?> 
       ^
- Arguments: view: <function my_view at 0x7f48d0bca3b0> 
       repeat: {...} (0) 
       req: <Request - at 0x7f48d29173d0> 
       renderer_name: templates/mytemplate.pt 
       project: foo 
       request: <Request - at 0x7f48d29173d0> 
       renderer_info: <RendererHelper - at 0x7f48d0bd1450> 
       context: <DefaultRootFactory None at 0x7f48d2917450> 

作爲背景,想法是避免到每年更新年份:

<div class="footer"> 
    &copy; Copyright 2008-2012, Agendaless Consulting. 
</div> 

回答

0

不應該有空格之間的第一?python。以下效果很好:

<div class="footer"> 
    <?python import time; year = time.strftime('%Y') ?> 
    &copy; Copyright 2008-${year}, Agendaless Consulting. 
</div> 

奇怪。

+1

也許這應該被報告爲一個錯誤。我認爲包含空格字符的語法更容易閱讀。如果它不解析,這是一個恥辱。 – malthe 2013-05-16 09:52:09