3

Can anybody give an example on using rest in getting and posting data from/to python server using Angularjs . Please provide an example for both client(angularjs) and server(python) .. where my sample client-side code is

var student_id = 12
$http({
    method:"POST" // or get
    url:       //url to the python file 
    data:     //this is what confusing me .. how to send that student id 

}).success(function(data){
     console.log(data);
   })

and in python i want to run a function which prints student id

def print_info(id):   ## here id is the student id that shall be recieved
  print "student id is %s" %id

here i want the js client to send that student_id value to python server where it should receive it and send that value of print_info function to the client.. Thanks in advance..

1 Answer 1

1

You can use it like this:

$http.post('<your_url>', data).success(function(data) {
    //handle the data returned
}, function(error) {
    //handle if an error is thrown
})

And the format of your data can be a json like this:

data = {
    "student_id": value
}
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks .. for showing me how to use it in client but can you also show me how to recieve this value in python server ?
are you using any framework? can you do a 'print request' in your method.
no i'm not using any frame work on server side .the python code is just having some functions to be called by client.
try sending the value as a parameter to your method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.