z3c.form和Plone - 在不使用自定义模板的情况下将自定义css文件添加到表单

时间:2014-03-09 13:36:05

标签: plone z3c.form

在我正在研究的项目中,我们定义了一个简单的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文件与此表单相关联,而不首先将其包装在带有表单的自定义页面模板中?

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:1)

如果您在自定义视图中使用此表单,则会在body类中添加类样式(类似template-yourviewname)。因此,您可以将CSS规则添加到主页CSS资源中,并在每个页面中加载,但为每个规则添加.template-yourviewname前缀。

相关问题