I get the following error message when I try to submit a new entity in GAE.
File "C:\Users\Chris\Documents\Web Apps\legalstudybuddy\main.py", line 179, in post
c = Courses(user=user, title=title)
TypeError: __init__() got an unexpected keyword argument 'user'
Here is my Python code:
class Courses(db.Model):
user = db.StringProperty(required = True)
title = db.StringProperty(required = True)
created = db.DateTimeProperty(auto_now_add = True)
class Courses(Handler):
def get(self, courses="", title="", signup_username="", login_logout=""):
if not self.user:
self.redirect('/login')
user = str(self.read_secure_cookie('user_id'))
courses = db.GqlQuery('SELECT * from Courses WHERE user = :user ORDER BY created DESC', user=user)
signup_username, login_logout = self.user_check()
self.render('courses.html', courses=courses,
title=title,
signup_username=signup_username,
login_logout=login_logout)
def post(self):
if not self.user:
self.redirect('/login')
user = str(self.read_secure_cookie('user_id'))
title = self.request.get('title')
if title:
c = Courses(user=user, title=title)
c.put()
self.redirect('/courses')
The unexpected keyword argument is from creating the entity not from the django template. Any help would be much appreciated.
You’re defining
Coursestwice. Once as the model:But also as the handler:
Since you define the handler second, that is what is stored as
Coursesin the current namespace. For example:I would suggest changing the name of the handler so that you don’t get the conflict you are getting now (where when you call
Courses(user=user), it is trying to call the handler instead of the model).