1

在我正在进行的一个项目中,我们定义了一个简单的 z3c.form,它看起来像这样。

class IImportCandidateForm(Interface):
    csv_file = NamedFile(title=_(u'CSV file'))

class ImportForm(form.Form):
    fields = field.Fields(IImportForm)
    ignoreContext = True

    def updateWidget(self):
        super(ImportForm, self).updateWidget()

    ... snip ...

    @button.buttonAndHandler(u'Import')
    def handleImport(self, action):
        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorMessage
            return 
        file = data["csv_file"].data

有没有办法将自定义 css 文件与此表单相关联,而无需先将其包装在带有表单的自定义页面模板中?

4

2 回答 2

2

不,没有。除非您使用表单包装器,否则表单的模板只会呈现表单而不是整个页面。

于 2014-03-10T00:58:24.420 回答
1

In you are using this form in a custom view, you have a class style added to the body class (something like template-yourviewname). So you can add you CSS rules to a main CSS resource, loaded in every page, but prefix every rule with .template-yourviewname.

于 2014-03-10T07:59:25.137 回答