如何将参数从一个视图传递到另一个视图 [英] How can I pass parameters from one view to another

查看:161
本文介绍了如何将参数从一个视图传递到另一个视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法执行此操作:我导航到所需的页面,但是变量似乎做错了。

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

@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>

我可以在表中显示页面的所有变量。但是,当我按下提交按钮时,我的诊断页面无法获得名称标签的内容。我不知道如何显示该值。

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 :问题基于此帖子:金字塔应用:如何将值传递到请求中.route_url?

ps: question is based on this post: Pyramid app: How can I pass values into my request.route_url?

推荐答案

一种解决方案正在使用url调度,如下所示:

a sollution is working with url dispatching like this:

_ init _。py:

_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从一个视图转移到另一个视图。

now you have your id from one view to another.

这篇关于如何将参数从一个视图传递到另一个视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆