[Answer]-Django/python the works of views and bringing in an API

1👍

This is a command line script that makes http requests to the yelp api. You probably don’t want to make such an external request within the context of a main request handler. Well, you could call a request handler that makes this call to yelp. Let’s see …

You could import the request function and instead of invoking it with command line options, call it yourself.

from yelp.business import request as yelp_req

def my_request_handler(request):
    json_from_yelp = yelp_req(...
    # do stuff and return a response

Making this kind of external call inside a request handler is pretty meh though (that is, making an http request to an external service within a request handler). If the call is in ajax, it may be ok for the ux.

This business.py is just an example showing you how to create a signed request with oauth2. You may be able to just import the request function and use it. OTOH, you may prefer to write your own (perhaps using the requests library). You probably want to use celery or some other async means to make the calls outside of your request handlers and/or cache the responses to avoid costly external http io with every request.

Leave a comment