0

Trying to implement a user registration form on a website I can't make user input to be added as a new user to the database. I'm using Flask with Peewee, and have:

nUser ={
        'email': request.form['e_mail'],
        'uname': request.form['username'],
        'pword': request.form['password'],                     
        'time': strftime('%Y-%m-%d %H:%M:%S')

}
nUser = User.create_or_get()

where nUser is temporary dict for new user. I should mention, that with the official peewee docs I tried nUser, created = User.create_or_get(nUser) what returned an error of too many arguments.

A code about User class is below (stored in separate .py, but there is from models import * up there):

class User(Model):
    email=TextField()
    uname=TextField(unique=True)
    pword=TextField()
    time=TextField()

    class Meta:
        database = db 

Although it looks like it "works" from a webuser side, no record is added to the database. Previously I did it with User.select().where(User.uname...... and it worked, but now I would like to switch to create_or_get() method since it would shorten my code and looks more efficient. Logging in for old users works, so the connection and access to the DB is fine. I would appreciate any hints.

davidism
  • 121,510
  • 29
  • 395
  • 339
adamczi
  • 343
  • 1
  • 7
  • 24
  • The documentation shows that the parameter is "**kwargs", so a single un-named dictionary will not work. Change it to `User.create_or_get(**nUser)`. – coleifer Aug 02 '16 at 08:13
  • it was already answered below, but thanks for help ;) – adamczi Aug 02 '16 at 09:25

1 Answers1

1

The official documentation that you link to show that create_or_get takes keyword arguments only. To pass a dict, you need to use the ** syntax:

User.create_or_get(**nuser)
Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895