0
我正在編寫一個API,並且註冊時出現問題:ValueError : The given username should be set
。在django上註冊
下面是代碼:
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 with such name or email already registered. Please, rewrite your 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 do 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')