Я хочу отправить ajax запрос с именем 'изменение пароля клиента'
здесь javascript код
function sendmailConfirm() {
var result = confirm("client(client@google.com) password will changed");
if (result == false) {
event.preventDefault();
alert('canceled.');
} else {
$.ajax({
'url': '/change/password',
'method': 'GET',
'data': {
'email':'password-change@pass.com',
},
'success':function(event){
alert('success!');
}
})
}
};
, а view.py -
class ChangePW(TemplateView):
def get(self, request):
if request.is_ajax():
user = User.objects.get(email='password-change@pass.com')
password = random_password_generate()
user.set_password(password)
user.is_active = False
user.save()
return JsonResponse({'status': 'success'})
я запускаю сервер и нажал кнопку
, но возникла ошибка
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 59753)
Traceback (most recent call last):
File "/Users/hanminsoo/.pyenv/versions/3.7.1/lib/python3.7/socketserver.py", line 647, in process_request_thread
self.finish_request(request, client_address)
File "/Users/hanminsoo/.pyenv/versions/3.7.1/lib/python3.7/socketserver.py", line 357, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/Users/hanminsoo/.pyenv/versions/3.7.1/lib/python3.7/socketserver.py", line 717, in __init__
self.handle()
File "/Users/hanminsoo/Desktop/issue/tving-ui/venv/lib/python3.7/site-packages/django/core/servers/basehttp.py", line 174, in handle
self.handle_one_request()
File "/Users/hanminsoo/Desktop/issue/tving-ui/venv/lib/python3.7/site-packages/django/core/servers/basehttp.py", line 182, in handle_one_request
self.raw_requestline = self.rfile.readline(65537)
File "/Users/hanminsoo/.pyenv/versions/3.7.1/lib/python3.7/socket.py", line 589, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [Errno 54] Connection reset by peer
----------------------------------------
Не могу понять, когда я удаляю user.set_password(password)
он работает
мой django версия '3.0.4' и python версия '3.7.1'
спасибо:)
ADD
утилит. py
import random
alphabet = 'abcdefghijklmnopqrstuvwxyz'
number = '1234567890'
symbol = '!#$%()*+,-./:;<>?@[]^_{|}~&'
def random_password_generate():
al = ''.join(random.choice(alphabet) for i in range(3))
nu = ''.join(random.choice(number) for i in range(3))
sy = ''.join(random.choice(symbol) for i in range(3))
pw = list(al + nu + sy)
random.shuffle(pw)
return ''.join(pw)