On 4 Nov 2015 05:45, "kk" <krm...@gmail.com> wrote: > > > > On Tuesday 03 November 2015 08:35 PM, Remco Gerlich wrote: >> >> Django code is just normal Python. Python can call REST APIs, sure (a nice library is Requests: docs.python-requests.org/en/latest/ ) >> > I got to see this, thanks, had a quick look and it exactly does what I want. > > >> Doing this in the view means that the user has to wait until the request ends before he gets a response. Possibly this will make the view too slow. You could also do the API requests in the background using Celery, and show the results some other way. > > > What do you mean doing it in the background? > How could it enhance the performance?
Imagine a slow web service that you consume (ie. a weather service that is used by so many people). Now when your user downloads the page that displays the service's data, they have to wait, because it takes a long time for your app to get the result from the service. With the suggested solution, there is a background task that runs on your server every 15 minutes or so. It fetches the data from the service and stores it in your database. Now when a user wants to see your page, Django gets the values from its own database, so the user doesn't have to wait for your app to get it from the server. As you can see, the tradeoff here is disk usage: you have to store the service's data on your machine. Also, if the data you fetch changes quickly (like in the stock market) this solution is not so good. In this case you may want to fetch the service's data from the generated page, e.g. with AJAX calls. Best, Gergely > happy hacking. > Krishnakant. > >> Remco Gerlich >> >> >> On Tue, Nov 3, 2015 at 12:44 PM, kk <krm...@gmail.com> wrote: >>> >>> Dear all, >>> I wish to know if I need to do some thing special for consuming a RESTfull server from some other provider? >>> What should I do in the views? >>> Do I need the complete DRF to do this? >>> Can I do this with just Django's views and then send data across to templates? >>> I mean, can I write views to connect and call the API, send and receive data and then send the output to the templates? >>> The encoding is in json when interacting with the remote REST API. >>> happy hacking. >>> Krishnakant. >>> >>> -- >>> 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+unsubscr...@googlegroups.com. >>> To post to this group, send email to django-users@googlegroups.com. >>> Visit this group at http://groups.google.com/group/django-users. >>> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/56389E08.10105%40gmail.com. >>> For more options, visit https://groups.google.com/d/optout. >> >> >> -- >> 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+unsubscr...@googlegroups.com. >> To post to this group, send email to django-users@googlegroups.com. >> Visit this group at http://groups.google.com/group/django-users. >> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFAGLK1rzNjgB2XxckRkZJqgOppwS6CiMxxwMd%2BmChnvKuy1Lw%40mail.gmail.com . >> For more options, visit https://groups.google.com/d/optout. > > > -- > 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+unsubscr...@googlegroups.com. > To post to this group, send email to django-users@googlegroups.com. > Visit this group at http://groups.google.com/group/django-users. > To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/56398D36.1080903%40gmail.com. > > For more options, visit https://groups.google.com/d/optout. -- 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+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CACczBULJYvmyOV4LuB6jKfS1U1x1x2jdej4kSWdAaxHm%2BGgjKg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.