发现很难解决这个基本问题。我正在使用python 2.7.10来跟踪使用python 3.4提供的烧瓶教程。我知道这两个版本之间存在一些差异,但似乎知识还不足以克服这种情况。我有python的业余级经验。感觉它与类定义有关,但无法确定它。是的,我经历了类似错误的解决方案,但无法将解决方案与我的问题联系起来。
Traceback (most recent call last):
File "manage.py", line 5, in <module>
from flask_init import app
File "/Users/sapp/Desktop/ude/flask_init/__init__.py", line 12, in <module>
from author import views
File "/Users/sapp/Desktop/ude/flask_init/author/views.py", line 3, in <module>
from form import RegisterForm
File "/Users/sapp/Desktop/ude/flask_init/author/form.py", line 5, in <module>
class RegisterForm(form):
TypeError: Error when calling the metaclass bases
module.__init__() takes at most 2 arguments (3 given)
我的目录结构:
├── __init__.py
├── __init__.pyc
├── author
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── form.py
│ ├── form.pyc
│ ├── models.py
│ ├── models.pyc
│ ├── views.py
│ └── views.pyc
├── blog
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── views.py
│ └── views.pyc
├── manage.py
├── requirements.txt
├── settings.py
├── settings.pyc
├── templates
│ ├── author
│ └── base.html
└── venv
├── bin
├── include
├── lib
└── pip-selfcheck.json
manage.py:
import os, sys
from flask_script import Manager, Server
from flask_init import app
manager = Manager(app)
manager.add_command("runserver", Server(
do something
))
if __name__ == "__main__":
manager.run()
form.py:
from flask_wtf import form
from wtforms import validators, StringField, PasswordField
from wtforms.fields.html5 import EmailField
class RegisterForm(form):
pass
init.py:
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config.from_object('settings')
db = SQLAlchemy(app)
import blog.views
from author import views
views.py:
from flask_init import app
from flask import render_template, redirect
from form import RegisterForm
@app.route('/register', method=('GET', 'POST'))
def register():
form = RegisterForm()
return render_template('author/register.html', form=form)
我选择不使用wtforms标记,因为我更关心的是2.7和3.4之间的元类,我更缺少什么。
答案 0 :(得分:4)
这与Python版本无关。
你在form.py中导入了错误的东西;您有form
而不是Form
。前者是一个模块,后者是类,这是你应该继承的。