Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8275293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:01:52+00:00 2026-06-08T08:01:52+00:00

I’m trying to access another service’s API, using my model’s fields as the keywords

  • 0

I’m trying to access another service’s API, using my model’s fields as the keywords in the API request. The URL would be like like so:

http://api.example.com/json/?first_name=FNAME&last_name=LNAME&key={key}

Here’s my code from views.py:

class ExamplePersonView(ListView):

    context_object_name = "example_person"
    template_name = "templates/example_person.html"

    def get_queryset(self):
        lname = get_object_or_404(ExamplePeople, lname__iexact=self.args[0])
        return ExamplePeople.objects.filter(lname=lname)

From what I understand, I’ll need to use AJAX to communicate between my page template and my views.py to send the request and then present the information on the page.

I’ve found several Django apps that make it easy to turn your models into a public API, but none that help you access API’s from another service. Does anyone know of an app like that?

If not, does anyone have a good understanding of using AJAX with Django to make the request and present it in the template?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T08:01:56+00:00Added an answer on June 8, 2026 at 8:01 am

    There’s several ways to communicate with a “foreign” API. There’s no necessity for ajax. Ajax is just for making background calls in a template, triggering whatever event you have in mind.

    But let’s say you want to communicate with the facebook GraphAPI to retrieve a profile

    http://graph.facebook.com/bill.clinton

    The standard result is serialized as JSON, which implements easily into AJAX or any JavaScript library, hence the name JavaScript Object Notation.

    So an example with AJAX might be:

    function callFacebook() {
        $.ajax({
            type: "GET",
            data: ({}),
            dataType: 'json',
            url: "http://graph.facebook.com/bill.clinton",
            success: function(data){
                alert("Hi I am former "+data.name);
            }
        });
    }
    callFacebook();
    

    Include this in your javascript file or within your template between script tags and you should get a nice alert message:

    Hi I am former President Bill Clinton

    Now you could turn this alert into something more meaningful, and put it within a h1 tag (not sure why this is meaningful)

    $("body").html("<h1>"+data.name+"</h1>");
    

    But sometimes you would want to retrieve data and do something with it server side in your application.

    So create a django urlpattern and view, e.g.:

    from urllib2 import urlopen
    from django.http import HttpResponse
    from django.utils import simplejson    
    
    def call_bill(request):
        url = "http://graph.facebook.com/bill.clinton"
        json = urlopen(url).read()
        # do whatever you want
        return HttpResponse(simplejson.dumps(json), mimetype="application/json")
    
    # add this to your url patterns
    url("^call_bill_clinton/$", call_bill)
    

    Now visit your url

    As a logic result, it’s also perfectly possible to trigger async events by some user action. Eg the URL parameter in the previously mentioned ajax example, could also be a django url like “/call_bill_clinton/”.

    <!-- add a button to call the function -->
    <button onclick="callFacebook();">Call Bill</button>
    
    function callFacebook() {
        $.ajax({
            type: "GET",
            data: ({}),
            dataType: 'json',
            url: "/call_bill_clinton/",
            success: function(data){
                alert("Hi I am former "+data.name+" and I came from Django");
            }
        });
    )
    // remove the auto call
    

    Furthermore ajax calls let you do the same trickery as http requests, you can use a variety of request methods combined with cool javascript events, like a beforeSend event

        beforeSend: function() {
            $('#loading').show();
        },
    

    Where the #loading could be something like:

       <div id="loading" style="display:none;">
            <img src="{% static "images/loading.gif" %}" />
        </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I'm making a simple page using Google Maps API 3. My first. One marker
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.