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 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)