def registe(request): if request.method == 'GET': return render(request, 'mine/registe.html') elif request.method == 'POST': # try: user = User() user.account = request.POST.get('account') user.password = genarate_password(request.POST.get('password')) user.name = request.POST.get('name') user.phone = request.POST.get('phone') user.addr = request.POST.get('addr') # user.img = 'axf.png' # 头像 imgName = user.account + '.png' imagePath = os.path.join(settings.MEDIA_ROOT, imgName) file = request.FILES.get('icon') with open(imagePath, 'wb') as fp: for data in file.chunks(): fp.write(data) user.img = imgName user.token = str(uuid.uuid5(uuid.uuid4(), 'register')) user.save() # 状态保持 request.session['token'] = user.token # 重定向 return redirect('axf:mine')
def register(request): if request.method == 'POST': user = User() # 用户账号 user.account = request.POST.get('account') # 用户密码加密 user.password = generate_password(request.POST.get('password')) # 用户名 user.name = request.POST.get('name') # 电话 user.tel = request.POST.get('tel') # 地址 user.address = request.POST.get('address') # 头像 imgName = user.account + '.png' imgPath = os.path.join(settings.MEDIA_ROOT, imgName) print(imgPath) file = request.FILES.get('file') print(file) with open(imgPath, 'wb') as fp: for data in file.chunks(): fp.write(data) user.img = imgName # token user.token = str(uuid.uuid5(uuid.uuid4(), 'register')) # 用户保存 user.save() # 状态保持 request.session['token'] = user.token # 注册成功之后的重定向 return redirect('axf:mine') elif request.method == 'GET': return render(request,'mine/register.html')
def registe(request): if request.method == 'GET': return render(request, 'mine/registe.html') elif request.method == 'POST': # try: user = User() user.account = request.POST.get('account') user.password = genarate_password(request.POST.get('password')) user.name = request.POST.get('name') user.phone = request.POST.get('phone') user.addr = request.POST.get('addr') # user.img = 'axf.png' # # # 头像 imgName = user.account + '.png' imagePath = os.path.join(settings.MEDIA_ROOT, imgName) file = request.FILES.get('icon') with open(imagePath, 'wb') as fp: # 打开文件,以读的形式 for data in file.chunks(): fp.write(data) user.img = imgName user.token = str(uuid.uuid5(uuid.uuid4(), 'register')) # user.token = '1' # user.save() # 状态保持 request.session['token'] = user.token # 重定向 return redirect('axf:mine') # return HttpResponse('注册') # except: # return HttpResponse('注册失败(该用户已被注册)') def checkaccount(request): account = request.GET.get('account') responseData = { 'msg': '账号可用', 'status': 1 # 1标识可用,-1标识不可用 } try: user = User.objects.get(account=account) responseData['msg'] = '账号已被占用' responseData['status'] = -1 return JsonResponse(responseData) except: return JsonResponse(responseData)