def inner(self, *args, **kwargs): if not self.session['user']: rep = BaseResponse() rep.summary = "未登录" self.write(json.dumps(rep.__dict__)) return func(self, *args, **kwargs)
def valid_username(request): if request.method == 'GET': username = request.GET.get('username') users = User.objects.filter(username=username) # https://code.ziqiangxuetang.com/django/django-queryset-api.html response = BaseResponse() if not users.exists(): response.status = True return HttpResponse(json.dumps(response.__dict__, cls=JsonCustomEncoder, ensure_ascii=False), content_type="application/json") else: response.summary = '用户名已存在' return HttpResponse(json.dumps(response.__dict__, cls=JsonCustomEncoder, ensure_ascii=False), content_type="application/json")