简体   繁体   中英

how to use model in django view

I want to use my model parameter for the API query parameter in Django View. How can I use this? Anyone can give me suggestions. Here curd is my model name. and consumer_type is the required query parameter

  from .models import curd
  for consumer_type in curd:
  response = requests.get("http://localhost:8280?ConsumerID="+consumer_type)

In the view, you can access the GET request like so:

if request.method == "GET":
    print(request.GET)

Then you could filter with:

cons_id = request.GET.get('ConsumerID', None)
if cons_id is None:
    raise Http404
else:
    mymodel = MyModel.objects.filter(...)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM