Advertisement
Guest User

Untitled

a guest
Oct 31st, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.22 KB | None | 0 0
  1. #This snippet here is the bit of code that enables my submit page to add a new user to my database  
  2.  def __init__(self, first, last, username, dob, password):
  3.         self.first = first
  4.         self.last = last
  5.         self.username = username
  6.         self.dob = dob
  7.         self.password = password
  8.  
  9. #This is my db model that is handling my database communication
  10. class User(db.Model):
  11.     __tablename__ = 'tbl_user'
  12.     can_create = False
  13.     id = db.Column('user_id', db.Integer, primary_key=True)
  14.     first = db.Column('user_first', db.String(15), nullable=False)
  15.     last = db.Column('user_last', db.String(25), nullable=False)
  16.     username = db.Column('user_username', db.String(80), unique=True, nullable=False)
  17.     dob = db.Column('user_dob', db.DateTime, nullable=False)
  18.     password = db.Column('user_password', db.String(80), nullable=False)
  19.     admin = db.Column('user_admin', db.Boolean, default=False, nullable=False)
  20.  
  21. #This is the code for my submit page and the form that is submitted on user account creation
  22.  
  23. <form action="" class="form-signin" method="POST">
  24.         <label for="inputFirst" class="sr-only">First Name</label>
  25.             <input type="name" value="{{request.form.inputFirst}}" name="inputFirst" id="inputFirst" class="form-control" placeholder="First Name" required autofocus>
  26.         <label for="inputLast" class="sr-only">Last Name</label>
  27.             <input type="name" value="{{request.form.inputLast}}" name="inputLast" id="inputLast" class="form-control" placeholder="Last Name" required autofocus>
  28.         <label for="inputEmail" class="sr-only">Email address</label>
  29.             <input type="email" value="{{request.form.inputEmail}}" name="inputEmail" id="inputEmail" class="form-control" placeholder="Email address" required autofocus>
  30.         <label for="dob" class="sr-only">Date of Birth</label>
  31.             <input type="date" value="{{request.form.dob}}" name="dob" id="dob" class="form-control" required autofocus>
  32.         <label for="inputPassword" class="sr-only">Password</label>
  33.             <input type="password" value="{{request.form.inputPassword}}" name="inputPassword" id="inputPassword" class="form-control" placeholder="Password" required>
  34.  
  35.         <button id="btnSignUp" class="btn btn-lg btn-primary btn-block" type="submit">Sign up</button>
  36.             <a href="{{url_for('login')}}">Already have an account? Log In Here!</a>
  37.         </form>
  38.  
  39. #when i have the def __init__ defined i can add the users with the submit page but i cannot modify them within the flask-admin console
  40. #alternatively when i do not have that i can modify the users with the flask-admin console but not add with submit.
  41. #when i have the __init__ defined i get this error
  42.  
  43. TypeError
  44. TypeError: __init__() takes exactly 6 arguments (1 given)
  45.  
  46. Traceback (most recent call last):
  47.   File "/home/ubuntu/myproject/myprojectenv/lib/python2.7/site-packages/flask/app.py", line 1985, in wsgi_app
  48.     response = self.handle_exception(e)
  49.   File "/home/ubuntu/myproject/myprojectenv/lib/python2.7/site-packages/flask/app.py", line 1540, in handle_exception
  50.     reraise(exc_type, exc_value, tb)
  51.   File "/home/ubuntu/myproject/myprojectenv/lib/python2.7/site-packages/flask/app.py", line 1982, in wsgi_app
  52.     response = self.full_dispatch_request()
  53.   File "/home/ubuntu/myproject/myprojectenv/lib/python2.7/site-packages/flask/app.py", line 1614, in full_dispatch_request
  54.     rv = self.handle_user_exception(e)
  55.   File "/home/ubuntu/myproject/myprojectenv/lib/python2.7/site-packages/flask/app.py", line 1517, in handle_user_exception
  56.     reraise(exc_type, exc_value, tb)
  57.   File "/home/ubuntu/myproject/myprojectenv/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request
  58.     rv = self.dispatch_request()
  59.   File "/home/ubuntu/myproject/myprojectenv/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request
  60.     return self.view_functions[rule.endpoint](**req.view_args)
  61.   File "/home/ubuntu/myproject/myprojectenv/lib/python2.7/site-packages/flask_admin/base.py", line 69, in inner
  62.     return self._run_view(f, *args, **kwargs)
  63.   File "/home/ubuntu/myproject/myprojectenv/lib/python2.7/site-packages/flask_admin/base.py", line 368, in _run_view
  64.     return fn(self, *args, **kwargs)
  65.   File "/home/ubuntu/myproject/myprojectenv/lib/python2.7/site-packages/flask_admin/model/base.py", line 1997, in create_view
  66.     model = self.create_model(form)
  67.   File "/home/ubuntu/myproject/myprojectenv/lib/python2.7/site-packages/flask_admin/contrib/sqla/view.py", line 1077, in create_model
  68.     if not self.handle_view_exception(ex):
  69.   File "/home/ubuntu/myproject/myprojectenv/lib/python2.7/site-packages/flask_admin/contrib/sqla/view.py", line 1060, in handle_view_exception
  70.     return super(ModelView, self).handle_view_exception(exc)
  71.   File "/home/ubuntu/myproject/myprojectenv/lib/python2.7/site-packages/flask_admin/contrib/sqla/view.py", line 1071, in create_model
  72.     model = self.model()
  73. TypeError: __init__() takes exactly 6 arguments (1 given)
  74.  
  75. I have been working on this for hours and cannot find the solution. google has listed several and i have tried all of them to no avail. at this point im at a loss for what to do and would appreciate any help in getting me pointed in the right direction. Thanks
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement