def show_photo(request): user = request.session.get("LOGIN_LOCAL_FLAG") current_user_id = user.get("id") sql = "select photo from t_user_info where user_id =%s" photo_dict = db.query(sql, params=(current_user_id, )) photo = photo_dict.get("photo") response = HttpResponse(photo) response.setdefault("Content-Disposition", "attachment;filename=a.png") response["Content-Type"] = "image/jp" return response
def personal(request): # 获取登陆用户的id user = request.session.get("LOGIN_LOCAL_FLAG") # 遍历该用户的注册信息 sql = "select * from t_user_info where user_id = %s" new = db.query(sql, params=(user.id, )) # 得到用户的头像 photo = new.get("photo") photo = HttpResponse(photo) new.pop("photo") return render(request, "personal.html", {"new": new, "photo": photo})
def comments(request): params = request.POST.dict() user = request.session.get("LOGIN_LOCAL_FLAG") userid = user.get("id") params["user_id"] = userid sql = "insert into t_resource_comment(content,star,comment_time,user_id,res_id)" \ "values(%(content)s, %(star)s, now(), %(user_id)s, %(res_id)s)" pk = db.update(sql, params=params) sql = "select t.*, f.nickname from t_resource_comment t left join t_user_info f " \ "on t.user_id=f.user_id where t.id=%s" comments = db.query(sql, params=(pk, )) return JsonResponse(data=comments)
def download(request, id): user = request.session.get("LOGIN_LOCAL_FLAG") userid = user.get("id") sql = "insert into t_resource_download(res_id,user_id,down_time) value (%s,%s,now())" db.update(sql, params=(id, userid)) sql = "select resource,resourceName,ext,content_type from t_resource where id = %s" resource = db.query(sql, params=(id, )) if resource: resourcePath = resource.get("resource") resourceName = resource.get("resourceName") ext = resource.get("ext") content_type = resource.get("content_type") with open(os.path.join("upload", resourcePath), "rb") as f: response = HttpResponse(f.read()) filename = f"{resourceName}.{ext}" filename = urlquote(filename) response["Content-Disposition"] = "attachment;filename=" + filename response["Content-type"] = content_type return response
def find(request, pk): sql = "select * from usernew where name1 = %s" user = db.query(sql, params=(pk, )) return render(request, "detail.html", user)
def change_new(request, pk): param = request.POST.dict() sql = "update usernew set name1=param[name1],pwd=param[pwd],tel=param[tel] where name1 = param[name1]" db.query(sql, param) return render(request, "change_new.html", param)
def change(request, pk): sql = "select * from usernew where name1 = %s" user = db.query(sql, params=(pk, )) return render(request, "change.html", user)
def photo(request, user_id): sql = "select photo from t_user_info where user_id =%s" photo_dict = db.query(sql, params=(user_id, )) photo = photo_dict.get("photo") return HttpResponse(photo)