[英]How can I pass parameters from one view to another
I can't get this to work: I navigate to the page I want, but I'm doing something wrong with the variables it seems. 我无法正常工作:我导航至所需的页面,但似乎变量似乎做错了。
views.py : 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 : 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>
I can show all the variables of page in my table. 我可以在表中显示页面的所有变量。 But when I press the submit button I can't get the content of the "name" label to my diagnose page.
但是,当我按下提交按钮时,我的诊断页面无法获得“名称”标签的内容。 I don't know how I can show the value.
我不知道如何显示价值。
ps : question is based on this post: Pyramid app: How can I pass values into my request.route_url? ps :问题基于此帖子: 金字塔应用程序:如何将值传递到我的request.route_url?
Instead of you'd need an input of some sort: 而不是您需要某种输入:
<input type="text" name="name" value="et werkt slet">
or type="hidden" if you don't want it displayed. 或输入=“ hidden”(如果您不想显示它)。
I'm still learning Pyramid as well, but I also wonder if from your code that the submit action is going to post to def hoofdpagina anyway. 我仍然还在学习Pyramid,但是我也想知道从您的代码来看,无论如何,submit操作是否将要发布到def hoofdpagina。 I think you might have to move your POST handling to:
我认为您可能必须将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))
In the init.py you have to add url dispatching (config.add_route). 在init.py中,您必须添加url调度(config.add_route)。 Your can get the data out of the url and pass on to another page like this.
您可以从url中获取数据,然后传递到另一个页面。
a sollution is working with url dispatching like this: 一种解决方案正在使用url调度,如下所示:
_ init _.py: _ init _.py:
config.add_route('diagnose1', '/diagnose1/{dosierid}')
views.py views.py
@view_config(route_name='diagnose1', renderer='templates/diagnose.pt')
def diagnose1(request):
tabeldata=''
dosierid = request.matchdict['dosierid']
now you have your id from one view to another. 现在,您拥有从一个视图到另一个视图的ID。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.