json - Registration on django -


i writing api , have problem registration: valueerror : given username should set.

here code:

def create_account(request):     if request.method == 'post':         username = request.post.get('username', '')         email = request.post.get('email', '')         check_username = user.objects.filter(username__exact=username)         check_email = user.objects.filter(email__exact=email)          if check_email.count() != 0:             if check_username.count() != 0:                check = json.dumps('user such name or email registered. please, rewrite name or email.')             return httpresponse(check, content_type='application/json')          password = request.post.get('password', '')         password2 = request.post.get('password2', '')          if password != password2:             wrong_password_message = json.dumps('the passwords not match. please, rewrite!')             return httpresponse(wrong_password_message, content_type='application/json')         else:             user = user.objects.create_user(username, email, password)             user.is_active = false             user.is_staff = false             user.is_superuser = false             user.save()     return httpresponse(json.dumps('hello new user!'), content_type='application/json') 

change line:

user = user.objects.create_user(username, email, password)` 

as

user = user.objects.create_user(username=username, email=email, password=password)` 

this should work.


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -