简体   繁体   English

如何将参数从一个视图传递到另一个视图

[英]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.

相关问题 如何在Django中将列表从一个视图传递到另一个视图? - How do I pass a list from one view to another in Django? 如何在python中将信息从一种方法传递到另一种方法 - how can I pass info from one method to another in python 如何在 Python 中将变量从一个生成器传递到另一个生成器? - How can I pass a variable from one generator to another in Python? 如何将变量从一类传递到另一类? - how can I pass variables from one class to another? 如何将变量从一个 Python 脚本传递到另一个? - How can I pass a variable from one Python Script to another? 如何将变量从一个 class 传递到 Python 中的另一个变量? - How can I pass a variable from one class to another in Python? 如何将变量从一个 Tkinter window 传递给另一个? - How can I pass variables from one Tkinter window to another? 如何将变量从一个视图传递到另一个视图并使用 Django 中最后一个视图的 URL 进行渲染? - How do I pass variables from one view to another and render with the last view's URL in Django? 如何将查询集或上下文字典从一个视图传递到另一个视图 - How to pass querysets or the context dictronary from one view to another view 将参数从一个笔记本传递到另一个 - Pass parameters from one notebook to another
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM