2013-03-04 194 views
0

我無法實現這個功能:我導航到了我想要的頁面,但是我看起來似乎在做錯誤的變量。如何將參數從一個視圖傳遞到另一個視圖

views.py

@view_config(http_cache=1,route_name='hoofdpagina', renderer='templates/hoofdpagina.pt') 
def hoofdpagina(request): 
page = DBSession.query(MyModel) #.filter_by(id='1').all() 

if 'form.submitted' in request.params: 
    name= request.params['name'] 
    page2=Page(name) 
    DBSession.add(page2) 
    return HTTPFound(location=request.route_url('view_page',pagename=name)) 
return dict(page=page) 


@view_config(route_name='diagnose', renderer='templates/diagnose.pt') 
def diagnose(request): 
    return request 
    kak = ['test1','test2','test3t'] 
    content = {"test1","test2","test3"} 
    return {'content' :content, 'test' :kak} 

hoofdpagina.pt

<form class="span12" action="/diagnose" method="POST"> 
    <table class="table table-hover"> 
     <thead class="header"> 
      <tr> 
       <th>D Nr.</th> 
       <th>Datum</th> 
       <th>Patient</th> 
       <th>Prior</th>        
      </tr> 
     </thead> 
     <tr tal:repeat="Page page" > 

       <td tal:content="Page.dosiernummer"></td> 
       <td tal:content="Page.dosiernummer"></td>         
       <td tal:content="Page.datum"></td> 
       <td tal:content="Page.naamPatient"></td> 
       <td tal:content="Page.prioriteit"></td>  
     </tr> 
    </table> 
</form> 

<form action="/diagnose" method="post"> 
    <input type="submit" value="Save" name="form.submitted" ></input> 
    <label name="name">et werkt slet</label> 
</form> 

我可以顯示網頁的所有變量在我的表。但是當我按下提交按鈕時,我無法將「名稱」標籤的內容獲取到我的診斷頁面。我不知道如何顯示價值。

PS:問題是根據這個帖子:Pyramid app: How can I pass values into my request.route_url?

+3

當您提交表單時,不會發送標籤元素的內容。 – professorsloth 2013-03-04 20:14:42

+0

看來你不僅是新來的金字塔,但對HTML/HTTP也 – bismigalis 2013-03-05 08:31:14

+0

請修復縮進。 – 2013-03-05 08:37:46

回答

0

一個sollution正在與URL調度這樣的:

_ 初始化 _.py:

config.add_route('diagnose1', '/diagnose1/{dosierid}') 

views.py

@view_config(route_name='diagnose1', renderer='templates/diagnose.pt') 
def diagnose1(request): 
    tabeldata='' 
    dosierid = request.matchdict['dosierid'] 

現在你已經你的身份從一個視圖到另一個視圖。

1

的你反而會需要某種形式的輸入:

<input type="text" name="name" value="et werkt slet"> 

或鍵入=「隱藏」如果你不希望顯示。

我還在學金字塔,但我也想知道,如果從你的代碼中提交的動作會發布到def hoofdpagina無論如何。我想你可能不得不將你的POST處理移動到:

@view_config(route_name='diagnose', renderer='templates/diagnose.pt') 
def diagnose(request): 
if 'form.submitted' in request.params: 
    name= request.params['name'] 
    page2=Page(name) 
    DBSession.add(page2) 
    return HTTPFound(location=request.route_url('view_page',pagename=name)) 
0

在init.py中,你必須添加url調度(config.add_route)。 你可以從網址中獲取數據並傳遞到另一個頁面。

相關問題