
IT/파이썬 2023. 4. 26.
Django - response 객체에 쿼리스트링 추가
response 보낼때 쿼리 스트링 붙여서 보내고 싶다면, 아래 코드를 참고하세요. response = redirect("order_view", pk=order.id) response["Location"] += "?" + request.POST.get("querystring") return response Location 이라는 필드가 있는 지 어케 아는지? 이렇게 작성을 해도 되고, from django.http import HttpResponse def my_view(request): # Get the query string from the request query_string = request.GET.get("querystring") # Create the URL with the query stri..

IT/파이썬 2021. 2. 13.
파이썬 flask Response JSON 리스트로 내보내기
파이썬 flask Response JSON 리스트로 내보내기 이거 쉬운데, 막상 해보고 고생해서 작성해둠음... JSON 의 리스트로 보내려고 하니 막 오류가 많이 떠서 고생 무튼 정답은 아래 일단, 스트링의 리스트로 만든다음 리스트 통째로 json.dumps(리스트) 를 이용해서 JSON 객체들의 리스트 형태로 리턴해 줄 수 있다. import json resultJSONt = [{"count": result.count()}] resultJSON = json.dumps(resultJSONt) print(resultJSON) # result = Customer.objects().to_json() return Response(resultJSON, mimetype="application/json", stat..
