python web py入门(6)-webpy在模板里使用code代码段错误的问题

像下面这段代码在WEBPY 0.40里会发现出错:

$def with (page_posts, page_count, page)

$code:
    grace = 5
    range = grace * 2
    start = page - grace if page - grace > 0 else 1
    end = start + range
    if end > page_count:
        end = page_count
        start = end - range if end - range > 0 else 1

    
+发帖
$for p in page_posts:
话题 作者 回应 最后回应
$trim_utf8(p['title'], 25) $p['username'] $p['comment_count'] $p['last_time']
$if start > 1: 1 ... $for i in range(start, end+1): $if i == page: $i $else: $i $if end < page_count: ... $page_count
运行这段代码会出错如下:
Traceback (most recent call last):
  File "D:\AI\python\web\caiforum\forumTest.py", line 41, in
    print(titled_render().list(page_posts, page_count, page))
  File "C:\Users\tony\AppData\Local\Programs\Python\Python36\lib\site-packages\web.py-0.40.dev0-py3.6.egg\web\template.py", line 1037, in template
    return self._base(t(*a, **kw))
  File "C:\Users\tony\AppData\Local\Programs\Python\Python36\lib\site-packages\web.py-0.40.dev0-py3.6.egg\web\template.py", line 904, in __call__
    return BaseTemplate.__call__(self, *a, **kw)
  File "C:\Users\tony\AppData\Local\Programs\Python\Python36\lib\site-packages\web.py-0.40.dev0-py3.6.egg\web\template.py", line 831, in __call__
    return self.t(*a, **kw)
  File "D:\AI\python\web\caiforum/templates\list.html", line 40, in __template__
    $i
TypeError: 'int' object is not callable


出错的原因是暂时没有找到,只能把这部分代码转换到forum.py文件,修改模板文件list.html,如下:

$def with (page_posts, page_count, page, start, end)

+发帖
$for p in page_posts:
话题 作者 回应 最后回应
$trim_utf8(p['title'], 25) $p['username'] $p['comment_count'] $p['last_time']
$if start > 1: 1 ... $for i in range(start, end+1): $if i == page: $i $else: $i $if end < page_count: ... $page_count

比特币源码入门教程

https://edu.csdn.net/course/detail/6998

深入浅出Matplotlib
https://edu.csdn.net/course/detail/6859

深入浅出Numpy
http://edu.csdn.net/course/detail/6149 

Python游戏开发入门

http://edu.csdn.net/course/detail/5690

你也能动手修改C编译器

http://edu.csdn.net/course/detail/5582



你可能感兴趣的:(webpy)