效果如下:
?
?
?核心功能:登录,晦棋,初级,中级
def login(request): ? ? if request.method == "POST": ? ? ? ? username = request.POST.get('username') ? ? ? ? password = request.POST.get('password') ? ? ? ? path ='./cheese/static/user/'+username+".txt" ? ? ? ? with open(path, 'r', encoding='utf-8') as f1: ? ? ? ? ? ? results = eval(f1.readlines()[0]) ? ? ? ? ? ? if password == results['password']: ? ? ? ? ? ? ? ? obj = JsonResponse({'data':'登陆成功!'}) ? ? ? ? ? ? ? ? # obj.set_cookie("is_login", True, 30) ?# cookie有效期为30秒 ? ? ? ? ? ? ? ? obj.set_cookie("username", username) ? ? ? ? ? ? ? ? return obj ? ? ? ? ? ? else: ? ? ? ? ? ? ? ? return JsonResponse({'data': '登陆失败!'}) ? ? else: ? ? ? ? return render(request,'login.html')
def meau(request): ? ? return render(request, 'meau.html')
def score(request): ? ? username = request.COOKIES.get("username") ? ? print(username) ? ? path = './cheese/static/user/' + username + ".txt" ? ? with open(path,'r',encoding='utf-8') as f1: ? ? ? ? results=eval(f1.readlines()[0]) ? ? ? ? score_old = results['score'] ? ? ? ? score_old += 1 ? ? ? ? results['score'] = score_old ? ? ? ? level=score_old//5 ? ? ? ? with open(path, 'w', encoding='utf-8') as f2: ? ? ? ? ? ? f2.write(str(results)) ? ? return JsonResponse({"data":results,'level':level})
|