Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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. 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:

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)

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.

like image 366
papu Avatar asked May 25 '16 08:05

papu


1 Answers

This has nothing to do with Python versions.

You're importing the wrong thing in your form.py; you have form instead of Form. The former is a module, the latter is the class, which is what you should be inheriting from.

like image 193
Daniel Roseman Avatar answered Oct 13 '22 05:10

Daniel Roseman