0

我将 WTForm 与 Google App Engine 一起使用。我想以班级的形式访问我的表格。

这适用于 djangoforms...

class PostForm(djangoforms.ModelForm):
  class Meta:
    model = BlogPost
    exclude = [ 'path', 'published', 'updated' ]

如何使用 WTforms 进行等效操作。

class PostForm(model_form):
  class Meta:
    model = BlogPost
    exclude = [ 'path', 'published', 'updated' ]

我通过回溯得到这个错误......

    Traceback (most recent call last):
  File "C:\Users\John\webdev\gae\google\appengine\runtime\wsgi.py", line 187, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "C:\Users\John\webdev\gae\google\appengine\runtime\wsgi.py", line 225, in _LoadHandler
    handler = __import__(path[0])
  File "C:\Users\John\webdev\gae\google\appengine\tools\dev_appserver_import_hook.py", line 676, in Decorate
    return func(self, *args, **kwargs)
  File "C:\Users\John\webdev\gae\google\appengine\tools\dev_appserver_import_hook.py", line 1858, in load_module
    return self.FindAndLoadModule(submodule, fullname, search_path)
  File "C:\Users\John\webdev\gae\google\appengine\tools\dev_appserver_import_hook.py", line 676, in Decorate
    return func(self, *args, **kwargs)
  File "C:\Users\John\webdev\gae\google\appengine\tools\dev_appserver_import_hook.py", line 1722, in FindAndLoadModule
    description)
  File "C:\Users\John\webdev\gae\google\appengine\tools\dev_appserver_import_hook.py", line 676, in Decorate
    return func(self, *args, **kwargs)
  File "C:\Users\John\webdev\gae\google\appengine\tools\dev_appserver_import_hook.py", line 1665, in LoadModuleRestricted
    description)
  File "C:\Users\John\webdev\gae-projects\cmwo-blog\admin.py", line 69, in <module>
    class PostForm(model_form):
TypeError: Error when calling the metaclass bases
    function() argument 1 must be code, not str
INFO     2012-07-30 14:40:31,700 dev_appserver.py:2952] "GET /admin/newpost HTTP/1.1" 500 -
4

1 回答 1

1

WTForms 的 model_form 不处理任何 Meta 内部类。也许您可以覆盖'__init__'PostForm 类的方法。

于 2012-07-31T07:05:14.467 回答