Tuesday, September 29, 2020

How to consume DJango Rest Api with DJango?

I am trying to consume a django api with django itself. Should I use class generic
views or normal views. Do you know what is the best approach?

Right now, to list items I am using TemplateView 

class RegionListView(TemplateView):
    template_name = 'region/list.html'

    def get(self,request):
        r = requests.get('http://127.0.0.1:8081/regions')
        regions = r.json()
        region_list = {'regions':regions}
        return render(request, self.template_name, region_list)

I need help to implement create and update views to use my api methods. Do you guys have any idea? 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/03abb212-8408-4fd7-8c5f-b78e9402bf38n%40googlegroups.com.

No comments:

Post a Comment