0

My views.py is below

def register(request):

if request.GET.get('name')and request.GET.get('surname')and request.GET.get('username') and request.GET.get('userpassword') and request.GET.get('repassword') and request.GET.get('email'):
name= request.GET.get('name')
surname= request.GET.get('surname')
    username = request.GET.get('username')
    userpassword = request.GET.get('userpassword')
    repassword = request.GET.get('repassword')
    email = request.GET.get('email')
    if name=="enter name"or surname=="enter surname"or username== "enter username" or userpassword=="pass" or repassword=="pass" or email=="enter mail":
    return render_to_response('hata.html')
if userpassword!=repassword:
    return render_to_response('hata1.html')
    if userpassword == repassword:
        User.objects.create_user(username=username, password=userpassword, email=email)
        User.first_name = name
        User.last_name = surname
        User.save()
        return HttpResponseRedirect('/login/')

I simpy try to add name and surname to the db during the reqistration process; however, when I run the server and make a registration, error occurs.

unbound method save() must be called with User instance as first argument (got nothing instead)

How can I fixed that? I will be really appreciated if you have any solution

As Devict mentioned, I did the neccessary changes in the code;however, I can not make the registered user log-in now. My log-in code is below

def login(request):
c = {}

if request.method == 'POST':
    username = request.POST['username']
    userpassword = request.POST['userpassword']
    username = authenticate(username=username, password=userpassword)
    if username is not None:
        if username.is_active:
            auth.login(request, username)
            return HttpResponseRedirect('/')

return render_to_response('login.html', c, context_instance=RequestContext(request) )
ealperen
  • 11
  • 2

1 Answers1

2

You can't do it that way. You have to instantiate a User object and then save it.

    new_user = User(username=username, password=userpassword, email=email)
    new_user.first_name = name
    new_user.last_name = surname
    new_user.save()
devict
  • 589
  • 4
  • 8
  • Thanks, but I can not make login the registered user now. – ealperen Jan 12 '14 at 13:47
  • it does not give any error, it actually create an account in database. But I was able to login before, now I can not. When I am trying to submit login information, it simply returns to login page – ealperen Jan 12 '14 at 14:22