简体   繁体   English

调用元类库时出错

[英]Error when calling the metaclass bases

Finding it very difficult to wrap around this basic problem. 发现很难解决这个基本问题。 I'm using python 2.7.10 to follow a flask tutorial being delivered using python 3.4. 我正在使用python 2.7.10来跟踪使用python 3.4提供的烧瓶教程。 I'm aware of some differences between the two versions, but seems that knowledge isn't enough to overcome this situation. 我知道这两个版本之间存在一些差异,但似乎知识还不足以克服这种情况。 I have amateur level experience in python. 我有python的业余级经验。 Have a feeling its got something to do with class definition, but unable to nail it. 感觉它与类定义有关,但无法确定它。 And yes i went through the solutions for similar error but wasn't able to relate the solution to my problem. 是的,我经历了类似错误的解决方案,但无法将解决方案与我的问题联系起来。

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)

My directory structure: 我的目录结构:

├── __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: 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: 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: 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: 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)

I chose not to tag with wtforms as i'm more concerned with what i'm missing when it comes to metaclasses between 2.7 and 3.4. 我选择不用wtforms标记,因为我更关心的是2.7和3.4之间的元类。

This has nothing to do with Python versions. 这与Python版本无关。

You're importing the wrong thing in your form.py; 你在form.py中导入了错误的东西; you have form instead of Form . 你有form而不是Form The former is a module, the latter is the class, which is what you should be inheriting from. 前者是一个模块,后者是类,这是你应该继承的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM