Hello, im new at python,and im learning how to develop a web app, with flask, and useing sql alchemy, so i have a form to register members to my author table, but im recibing the following error:
TypeError: __init__() takes 1 positional argument but 6 were given
i have the folders author, and blog
so in my author folder i have my models .py as follow
TypeError: __init__() takes 1 positional argument but 6 were given
i have the folders author, and blog
so in my author folder i have my models .py as follow
from flask_blog import db class Author(db.Model): id = db.Column(db.Integer, primary_key=True) fullname = db.Column(db.String(80)) email = db.Column(db.String(35), unique=True) username = db.Column(db.String(80), unique=True) password = db.Column(db.String(80)) is_author = db.Column(db.Boolean) def __init__(self, fullname, email, username, password, is_author=False): self.fullname = fullname self.email = email self.username = username self.password = password self.is_author = is_author def __repr__(self): return '<Author %r>' % self.usernameso the problem appears in my views.py which is in my blog folder
from flask_blog import app from flask import render_template, redirect, flash, url_for # noqa : F401 from blog.form import SetUpForm from flask_blog import db from author.models import Author from blog.models import Blog @app.route('/') @app.route('/index') def index(): return"Hello World" @app.route('/admin') def admin(): blogs = Blog.query.count() if blogs == 0: return redirect(url_for('setup')) return render_template('blog/admin.html') @app.route('/setup', methods=('GET', 'POST')) def setup(): error = "" form = SetUpForm() if form.validate_on_submit(): author = Author( form.fullname.data, form.email.data, form.username.data, form.password.data, True ) db.session.add(author) db.session.flush() if author.id: blog = Blog( form.name.data, author.id ) db.session.add(blog) db.session.flush() else: db.session.rollblack() error = "Error creating user" if author.id and blog.id: db.session.comit() flash(" Blog created ") return redirect(url_for('admin')) else: db.session.rollback() error = "Error creating blog " # noqa : F841 return render_template('blog/setup.html', form=form)so i dont know where the problem is, cause my instance of Author, have 5 values, because the id is an autoincrmentable value, but somehow it is expecting one argument
Moderator: nilamo: Traceback was added in the other thread
Quote:
Error:sorry miss the tracerback Traceback (most recent call last): File "C:\Users\IGNACI~1\Desktop\PROGRA~1\python\FLASK_~2\venv\lib\site-packages\flask\app.py", line 2309, in __call__ return self.wsgi_app(environ, start_response) File "C:\Users\IGNACI~1\Desktop\PROGRA~1\python\FLASK_~2\venv\lib\site-packages\flask\app.py", line 2295, in wsgi_app response = self.handle_exception(e) File "C:\Users\IGNACI~1\Desktop\PROGRA~1\python\FLASK_~2\venv\lib\site-packages\flask\app.py", line 1741, in handle_exception reraise(exc_type, exc_value, tb) File "C:\Users\IGNACI~1\Desktop\PROGRA~1\python\FLASK_~2\venv\lib\site-packages\flask\_compat.py", line 35, in reraise raise value File "C:\Users\IGNACI~1\Desktop\PROGRA~1\python\FLASK_~2\venv\lib\site-packages\flask\app.py", line 2292, in wsgi_app response = self.full_dispatch_request() File "C:\Users\IGNACI~1\Desktop\PROGRA~1\python\FLASK_~2\venv\lib\site-packages\flask\app.py", line 1815, in full_dispatch_request rv = self.handle_user_exception(e) File "C:\Users\IGNACI~1\Desktop\PROGRA~1\python\FLASK_~2\venv\lib\site-packages\flask\app.py", line 1718, in handle_user_exception reraise(exc_type, exc_value, tb) File "C:\Users\IGNACI~1\Desktop\PROGRA~1\python\FLASK_~2\venv\lib\site-packages\flask\_compat.py", line 35, in reraise raise value File "C:\Users\IGNACI~1\Desktop\PROGRA~1\python\FLASK_~2\venv\lib\site-packages\flask\app.py", line 1813, in full_dispatch_request rv = self.dispatch_request() File "C:\Users\IGNACI~1\Desktop\PROGRA~1\python\FLASK_~2\venv\lib\site-packages\flask\app.py", line 1799, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "C:\Users\Ignacio Muriel\Desktop\programacion\python\flask_blog\blog\views.py", line 34, in setup True TypeError: __init__() takes 1 positional argument but 6 were given