QueryParameter

배찬영·2021년 6월 10일
0

Django

목록 보기
7/10

PostMan을 이용한 QueryParameter

class ProductDetailView(View):
    def get(self, request):
        try:
            product_id  = request.GET['product_id']
            product     = Product.objects.get(id=product_id)
            images      = Image.objects.filter(product_id=product.id)
            tags        = ProductTag.objects.filter(product_id=product.id)

뷰.py에 queryparameter를 이용하기 위해 request.GET['product_id']을 사용하여 Key와 Value를 받아 온다.
requust.GET.get('product_id',None)도 가능하다.

  • 위에 사진 처럼 Params의 KEY, VALUE를 지정 해준다.
    (http://localhost:8000/main 까지 지정해주면 된다. 뒷 부분은 자동 생성)
  • send를 하면 값이 잘 나옴을 볼 수있다.

url 지정시 RESTful API의 맞춰서 지정 할 수 있도록 한다.

profile
안녕하세요

0개의 댓글