[英]How can I pass parameters from one view to another
我无法正常工作:我导航至所需的页面,但似乎变量似乎做错了。
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 :问题基于此帖子: 金字塔应用程序:如何将值传递到我的request.route_url?
而不是您需要某种输入:
<input type="text" name="name" value="et werkt slet">
或输入=“ hidden”(如果您不想显示它)。
我仍然还在学习Pyramid,但是我也想知道从您的代码来看,无论如何,submit操作是否将要发布到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))
在init.py中,您必须添加url调度(config.add_route)。 您可以从url中获取数据,然后传递到另一个页面。
一种解决方案正在使用url调度,如下所示:
_ init _.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']
现在,您拥有从一个视图到另一个视图的ID。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.