Django Rest Framework: Get Data from an external apis

67 views
Skip to first unread message

tapha kebe

unread,
Jan 25, 2018, 12:07:57 PM1/25/18
to Django users
Hi,

i'm trying to get my data from an external api (example: https:api.test.com/consumers).  And i would like to know, if i have to build the extenal Api URL in my urls.py like this:
    url(r'^(?P<api.test.com/consumers)>[0-9]+)$/', views.get, name="get"),



 or you have any other good idea?

Thanks 

Jani Tiainen

unread,
Jan 25, 2018, 12:11:12 PM1/25/18
to django...@googlegroups.com

Hi,

You can't do that. Django URL configs are URLS that are routed to views withing Django and you can't define url that would access external sources.

To access external sources you have to do that in your endpoint API to call remote resource, for example by using requests library.
--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/264cbb11-8f02-4730-926f-8e0ab9150fc8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

-- 
Jani Tiainen

Andy

unread,
Jan 25, 2018, 9:39:43 PM1/25/18
to Django users
you dont have to define any route when getting data from an external api, just use requests.get('https://api.test.com/consumers') to get your data
Reply all
Reply to author
Forward
0 new messages