【问题标题】:Turbogears Toscawidget not workingTurbogears Toscwidget 不工作
【发布时间】:2018-01-22 17:05:19
【问题描述】:

我在这个guide 和这个guide 中进行了搜索,并按照示例进行了操作。 这是我在 controllers/root.py 中的控制器:

@expose('rubrica.templates.submitForm')
def add(self, *args, **kw):  
    return dict(page='submitForm', form=SubmitForm)

@expose()
def save_record(self, **kw):
    print('save_record')
    new_contact = Contact(name = kw['name'], phone = kw['phone'])
    model.DBSession.add(new_contact)
    flash(message = "Added new contact")
    redirect('/index')

这是 SubmitForm.py:

import tw2.core as twc
import tw2.forms as twf
class SubmitForm(twf.Form):
    class child(twf.TableLayout):
        name = twf.TextField(size = 20)
        phone = twf.TextField(size = 20)
        action = '/save_record'
        submit = twf.SubmitButton(value = 'Submit')

这是模板:

<head py:block="head" py:strip="True">
    <title py:block="master_title">Aggiungi Contatto</title>
</head>
<body py:block="body" py:strip="True">
    <div>
        ${form.display(value = dict(title = 'Inserisci i dati'))}
    </div>
</body>
</html>

问题是 save_record 没有被调用(action = '/save_record' 应该调用它,但没有任何反应) 我不知道为什么.. 猜我做错了什么,或者缺少什么但我无法得到它:)

感谢您的帮助!

【问题讨论】:

    标签: forms python-2.7 turbogears2


    【解决方案1】:

    actionsubmitForm 的属性,但您在Layout 中指定它们。将 actionsubmit 属性移出父范围,它应该可以按预期工作:

    import tw2.core as twc
    import tw2.forms as twf
    
    class SubmitForm(twf.Form):
        class child(twf.TableLayout):
            name = twf.TextField(size = 20)
            phone = twf.TextField(size = 20)
    
        action = '/save_record'
        submit = twf.SubmitButton(value = 'Submit')
    

    【讨论】:

      猜你喜欢
      • 2012-03-30
      • 1970-01-01
      • 2019-02-23
      • 2010-11-21
      • 2011-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-17
      相关资源
      最近更新 更多