添加必要的异常捕获
This commit is contained in:
parent
d01b0106cb
commit
3520699304
@ -41,25 +41,28 @@ def add_user(request):
|
||||
:param request: POST提交注册信息
|
||||
:return: 注册结果
|
||||
"""
|
||||
username = request.POST.get("username")
|
||||
pwd_base64 = base64.b64encode(request.POST.get("pwd"))
|
||||
pwd = make_password(pwd_base64)
|
||||
email = request.POST.get("email")
|
||||
phone = request.POST.get("phone")
|
||||
create_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
last_login_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
print(username, pwd, email, phone)
|
||||
avatar = request.FILES.get("avatar")
|
||||
auth_models.User.objects.create(
|
||||
username=username,
|
||||
pwd=pwd,
|
||||
email=email,
|
||||
phone=phone,
|
||||
create_time=create_time,
|
||||
last_login_time=last_login_time,
|
||||
avatar=avatar
|
||||
)
|
||||
return HttpResponse("添加用户成功")
|
||||
try:
|
||||
username = request.POST.get("username")
|
||||
pwd_base64 = base64.b64encode(request.POST.get("pwd"))
|
||||
pwd = make_password(pwd_base64)
|
||||
email = request.POST.get("email")
|
||||
phone = request.POST.get("phone")
|
||||
create_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
last_login_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
print(username, pwd, email, phone)
|
||||
avatar = request.FILES.get("avatar")
|
||||
auth_models.User.objects.create(
|
||||
username=username,
|
||||
pwd=pwd,
|
||||
email=email,
|
||||
phone=phone,
|
||||
create_time=create_time,
|
||||
last_login_time=last_login_time,
|
||||
avatar=avatar
|
||||
)
|
||||
return HttpResponse("添加用户成功")
|
||||
except Exception as e:
|
||||
return HttpResponse(f"报错了:{e}")
|
||||
|
||||
|
||||
@require_POST
|
||||
@ -81,4 +84,4 @@ def login_user(request):
|
||||
except binascii.Error as e:
|
||||
return HttpResponse("base64解码失败")
|
||||
except Exception as e:
|
||||
return HttpResponse("报错了")
|
||||
return HttpResponse(f"报错了:{e}")
|
||||
|
Loading…
Reference in New Issue
Block a user