bottle使用模版文件传递参数
    
    
    
        
            发布时间 : 
        
    
    
        
        字数:329
        
        
        
            阅读 :
                
            
        
        
        
    
    
    
    
        
    
    
    
      
        | 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 
 | 
 from bottle import route, run, template
 
 
 class myobj:
 def __init__(self,x=0,y=0):
 self.x,self.y = x,y
 def disp(self):
 pass
 return (self.x, self.y)
 
 
 @route('/<name>')
 def index(name='Stranger'):
 age = 22
 weight = 60
 score = {'ch':100, 'math':100}
 obj = myobj(1,1)
 mine = dict(name=name, age=age, weight=weight, score=score, obj=obj)
 return template('bottle使用模版文件传递参数.tpl',**mine)
 
 
 
 
 run(port='80',debug=True, reloader=True)
 
 | 
file: bottle使用模版文件传递参数.tpl
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 
 | <!doctype html><html>
 <head>
 <meta charset='utf-8'>
 <title>	标签名	</title>
 <h2>标题			</h2>
 </head>
 
 <body>
 
 Hello {{name}}!	<br/>
 I'm {{age}}.<br/>
 My weight: {{int(weight)}}.<br/>
 
 My obj: {{obj.disp()}}<br/>
 
 <br/>
 % if score:
 <table>
 <tr>
 <td>subject</td>
 <td>score</td>
 </tr>
 %for (sub,score) in score.items():
 <tr>
 <td>{{sub}}</td>
 <td>{{score}}</td>
 </tr>
 %end
 </table>
 % else:
 没有得到分数
 % end
 
 </body>
 </html>
 
 
 
 | 
 转载请注明来源 https://tianweiye.github.io