def categoryInfo(request): response = {} response['data'] = {} response['errorMsg'] = "" _shopId = request.session.get('shopId') if not _shopId: response['code'] = 1 response['errorMsg'] = '请先登录' return HttpResponse(json.dumps(response),content_type="application/json") ##################JUDGE############ _lastLoginTime = request.session.get('lastLoginTime') if not _lastLoginTime: response['code'] = 1 response['errorMsg'] = '请先登录' return HttpResponse(json.dumps(response),content_type="application/json") try: shop = Shop.objects.get(id = _shopId) except ObjectDoesNotExist: response['code'] = 1 response['errorMsg'] = '请先登录' return HttpResponse(json.dumps(response,ensure_ascii=False),content_type="application/json") if _lastLoginTime != shop.lastLoginTime: response['code'] = 1 response['errorMsg'] = '上次登录失效,请重新登录' return HttpResponse(json.dumps(response),content_type="application/json") ####################END################# _method = request.REQUEST.get('method') if _method == None or _method == '': response['code'] = -1 response['errorMsg'] = '获取method失败' return HttpResponse(json.dumps(response,ensure_ascii=False),content_type="application/json") _method = str(_method) if _method == '0': _name = request.REQUEST.get('categoryName') if _name == None or _name == '': response['code'] = -1 response['errorMsg'] = '请输入名字' return HttpResponse(json.dumps(response,ensure_ascii=False),content_type="application/json") category = Category(categoryName = _name,shop = shop) try: category.save() except Exception,e: print('e') response['code'] = -1 response['errorMsg'] = '保存类别失败' return HttpResponse(json.dumps(response),content_type="application/json") response['code'] = 0 response['data'] = {"categoryName":category.categoryName,"categoryId":category.id} return HttpResponse(json.dumps(response),content_type="application/json")