Hi want to save the information being posted to the database. I am using python flask and this is the way i attempted it.
@app.route('/add-new-song',methods=['GET','POST'])
def add_new_song():
form = NewSongForm(request.form)
if form.validate_on_submit():
new_song = SongBook()
form.populate_obj(new_song)
db.session.add(new_song)
db.session.commit()
return render_template('add-new-song.html',form=form)
When i try this i get this error:
TypeError: __ init __() takes exactly 6 arguments (1 given)
Any thoughts on how to do this?
here are the models
class SongBook(db.Model):
id = db.Column(db.Integer, primary_key=True)
song_book = db.Column(db.String(80))
title = db.Column(db.String(120))
artist = db.Column(db.String(120))
disc_number = db.Column(db.String(120))
track_number = db.Column(db.String(120))
def __init__(self, song_book, title, artist, disc_number, track_number):
self.song_book = song_book
self.title = title
self.artist = artist
self.disc_number = disc_number
self.track_number = track_number
trace back
TypeError: __init__() takes exactly 6 arguments (1 given)
Traceback (most recent call last)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 2000, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1991, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/usr/local/lib/python2.7/dist-packages/flask_restful/__init__.py", line 271, in error_router
return original_handler(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1567, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1988, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1641, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python2.7/dist-packages/flask_restful/__init__.py", line 271, in error_router
return original_handler(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1544, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1639, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1625, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/a/Desktop/ddtkaraoke.com/app.py", line 118, in add_new_song
new_song = SongBook()
TypeError: __init__() takes exactly 6 arguments (1 given)