2017-09-13 82 views
0

使用web2py的RESTful服務,我想下面的HTML瀏覽器呈現導航到這個鏈接(http://127.0.0.1:8000/app/default/api/example_data.html_table/?limit=1)後:如何從web2py RESTFUL服務創建自定義通用視圖?

<div><table><thead><tr><th>example_data.id</th><th>example_data.Firstname</th><th>example_data.Lastname</th><th>example_data.Age</th></tr></thead><tbody><tr class="w2p_odd odd"><td>1</td><td>SUUUUPPPEEEERRRR LONGGGGG FIRSTTTT NAMEEEE</td><td>Smith</td><td>1</td></tr></tbody></table></div> 

不過,我目前收到以下:

<div><table><thead><tr><th>example_data.id</th><th>example_data.Firstname</th><th>example_data.Lastname</th><th>example_data.Age</th></tr></thead><tbody><tr class="w2p_odd odd"><td>1</td><td>SUUUUPPPEEEER...</td><td>Smith</td><td>1</td></tr></tbody></table></div> 

不同的是,web2py會被縮短「SUUUUPPPEEEERRRR LONGGGGG FIRSTTTT NAMEEEE」到「SUUUUPPPEEEER ......」但我需要整個文本

我查看名爲generic.html_table產生,這是以下:

{{=BEAUTIFY(response._vars[next(iter(response._vars))])}} 

控制器

@request.restful() 
def api(): 
    response.view = 'generic.' + request.extension 
    def GET(*args,**vars): 
     patterns = 'auto' 
     parser = db.parse_as_rest(patterns,args,vars) 
     return dict(content=parser.response) 
    def POST(table_name,**vars): 
     if 'id' in vars.keys(): 
      return db[table_name].update_or_insert(db[table_name]._id == vars['id'],**vars) 
     else: 
      return db[table_name].validate_and_insert(**vars) 
    def PUT(table_name,**vars): 
     record_id = vars['id'] 
     return db(db[table_name]._id==record_id).update(**vars) 
    def DELETE(table_name,record_id): 
     return db(db[table_name]._id==record_id).delete() 
    return dict(GET=GET, POST=POST, PUT=PUT, DELETE=DELETE) 

模型

db.define_table('example_data', Field('Firstname', 'string'),Field('Lastname', 'string'),Field('Age', 'integer')) 

我也嘗試了以下觀點:

{{=response._vars[next(iter(response._vars))]}} 

RESULT(名字仍然切斷):

<table><thead><tr><th>example_data.id</th><th>example_data.Firstname</th><th>example_data.Lastname</th><th>example_data.Age</th></tr></thead><tbody><tr class="w2p_odd odd"><td>1</td><td>Jill</td><td>Smith</td><td>1</td></tr><tr class="w2p_even even"><td>2</td><td>Eve</td><td>Jackson</td><td>33</td></tr><tr class="w2p_odd odd"><td>3</td><td>afdaskfdlasjf...</td><td>Jackson</td><td>33</td></tr><tr class="w2p_even even"><td>4</td><td>SUUUUPPPEEEER...</td><td>Jackson</td><td>33</td></tr></tbody></table> 

我也嘗試了以下觀點:

{{=XML(response._vars[next(iter(response._vars))])}} 

RESULT(失去了所有的HTML格式):

example_data.id,example_data.Firstname,example_data.Lastname,example_data.Age 1,吉爾,史密斯,1 2,伊芙,傑克遜,33 3,afdaskfdlasjfkdlsjfklajdfskasjfklsdajfdklsajfklsajfdskalfdjsakldfjklasfjkdlsajfdsakljdklsadcjklasjcklsjackldsjakfldajsfklasdfjklasjfdklajfdsklsjafkldasjfkldasjkldsjcklajsckljackldajsdfklfjkalsncklacnkalsdfjkldasn ckldasjckljsdaklfdnfkldsajfdklasjldsk,傑克遜,33 4,SUUUUPPPEEEERRRR LONGGGGG FIRSTTTT NAMEEEE,傑克遜,33

回答

0

所有的這些方法最終導致在DAL Rows對象被傳遞到SQLTABLE在視圖中呈現。默認情況下,字段被截斷爲16個字符。如果你想改變這種情況,你必須明確地撥打SQLTABLE

{{=SQLTABLE(content, truncate=100)}}