当创建用户时,我正在使用Django创建用户和对象。但是有一个错误
__init__() got an unexpected keyword argument 'user'
打电话时register()view.py中的功能。该功能是:
def register(request): '''signup view''' if request.method=="POST": form=RegisterForm(request.POST) if form.is_valid(): username=form.cleaned_data["username"] email=form.cleaned_data["email"] password=form.cleaned_data["password"] user=User.objects.create_user(username, email, password) user.save() return HttpResponseRedirect('/keenhome/accounts/login/') else: form = RegisterForm() return render_to_response("polls/register.html", {'form':form}, context_instance=RequestContext(request)) #This is used for reinputting if failed to register else: form = RegisterForm() return render_to_response("polls/register.html", {'form':form}, context_instance=RequestContext(request)) 对象类是:
class LivingRoom(models.Model): '''Living Room object''' user = models.OneToOneField(User) def __init__(self, temp=65): self.temp=temp TURN_ON_OFF = ( ('ON', 'On'), ('OFF', 'Off'), ) TEMP = ( ('HIGH', 'High'), ('MEDIUM', 'Medium'), ('LOW', 'Low'), ) on_off = models....